枚举是JDK1.5版本新增的特性(泛型、For-each等如今被广泛应用的特性也是由JDK1.5时所新增的),另外到了JDK1.6后switch语句支持枚举类型。
枚举与静态final区别
枚举的好处以及与常量类的区别
valueOf()通过常量名获取对应的枚举实例。
shapType type = shapType.valueOf("OVAL");
System.out.println(type);
java.lang.Enum
enum具有如下的属性:
每个enum常量只有一个实例。
泛型类型必须是java.lang.Throwable类的一个直接或间接子类。
public class GenericListDemo1 {
public static void main(String[] args) {
// without generics
List stringList1 = new ArrayList();
stringList1.add("Java");
stringList1.add("without generics");
// cast to java.lang.String
String s1 = (String) stringList1.get(0);
System.out.println(s1.toUpperCase());
// with generics and diamond
List<String> stringList2 = new ArrayList<>();
stringList2.add("Java");
stringList2.add("with generics");
// no type casting is necessary
String s2 = stringList2.get(0);
System.out.println(s2.toUpperCase());
}
}
使用?通配符
如果你声明一个List
实现了aType的一个类的实例
示例:
List<?> myList = new ArrayList<?>() 错误
List<Object> myList = new ArrayList<>()
List<? extends Number> 定义上界
List<? SUPER Integer> 作为一个方法参数的类型
public static final <T> List<T> emptyList()
集合是将其他对象组织到一起的一个对象,集合也叫容器,它提供了一种方法来存储、访问和操作其元素。
Map(keySet,values,entrySet)
需要通过Arrays.sort或Collections.sort来支持排序的任何类,都必须实现Comparable接口。
public class Elephant implements Comparable {
public float weight;
public int age;
public float tuskLength;
public int compareTo(Object obj) {
Elephant anotherElephant = (Elephant) obj;
if (this.weight > anotherElephant.weight) {
return 1;
} else if (this.weight < anotherElephant.weight) {
return -1;
} else {
// both elephants have the same weight, now
// compare their age
return (this.age - anotherElephant.age);
}
}
}
java.time.format.DateTimeFormatter可以格式化一个本地日期或带时区的日期时间。
所有集合类都位于java.util包下。Java的集合类主要由两个接口派生而出:Collection和Map,Collection和Map是Java集合框架的根接口,这两个接口又包含了一些子接口或实现类。
集合接口:6个接口(短虚线表示),表示不同集合类型,是集合框架的基础。
抽象类:5个抽象类(长虚线表示),对集合接口的部分实现。可扩展为自定义集合类。
实现类:8个实现类(实线表示),对接口的具体实现。
Collection 接口是一组允许重复的对象。
Set 接口继承 Collection,集合元素不重复。
List 接口继承 Collection,允许重复,维护元素插入顺序。
Map接口是键-值对象,与Collection接口没有什么关系。
9.Set、List和Map可以看做集合的三大类:
List集合是有序集合,集合中的元素可以重复,访问集合中的元素可以根据元素的索引来访问。
Set集合是无序集合,集合中的元素不可以重复,访问集合中的元素只能根据元素本身来访问(也是集合里元素不允许重复的原因)。
Map集合中保存Key-value对形式的元素,访问时只能根据每项元素的key来访问其value。
Collection接口是处理对象集合的根接口,其中定义了很多对元素进行操作的方法。Collection接口有两个主要的子接口List和Set。
(statistics.sh脚本的运行结果截图)
double d = 0.1 + 0.1 + 0.1, System.out.println(i);的结果是0.3.
A .正确
B .错误
Java中,动态字符串优先使用()类
A .字符数组
B .StringBuffer
C .StringBuilder
D .String
查阅资料:
执行速度:StringBuilder > StringBuffer > String
线程安全:StringBuffer线程安全.StringBuilder线程不安全
String适用与少量字符串操作,StringBuilder适用单线程下在字符缓冲区下进行大量操作的情况,StringBuffer使用多线程下在字符缓冲区进行大量操作的情况。
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 150/200 | 2/2 | 20/20 | |
第二周 | 200/400 | 1/3 | 20/40 | |
第三周 | 100/500 | 1/4 | 10/50 | |
第四周 | 200/700 | 1/5 | 15/65 |
计划学习时间:15小时
实际学习时间:15小时
原文:https://www.cnblogs.com/Shambryce/p/10590944.html