枚舉是JDK1.5版本新增的特性(泛型、For-each等現在被普遍應用的特性也是由JDK1.5時所新增的),另外到了JDK1.6後switch語句支持枚舉類型。
枚舉與靜態final區別html
枚舉的好處以及與常量類的區別java
valueOf()經過常量名獲取對應的枚舉實例。git
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小時