java集合工具包包含了常用的數據結構:集合、鏈表、隊列、棧、數組、映射等。Java集合工具包位置是java.util.*;其總體框架圖如下所示:

一個有序且有索引的容器,允許重復值的出現。
一個無序的唯一對象的容器,不允許重復值出現。
一個基于鍵值對以及哈希的數據結構,不允許相同的鍵值出現。
List 允許,Set 不允許,而Map中鍵對象必須唯一。
List 有序,Set 無序,而Map也沒有規定順序。
某些 Set 實現比如 LinkedHashSet 還是保持了每個元素的插入順序。此外 SortedSet 的實現 TreeSet , SortedMap的實現 TreeMap 也通過 Comparator 或者 Comparable 維護了一個排序順序。List允許多個null值,Set允許一個null值,Map可以有多個null值和最多一個null鍵。
Hashtable 既不允許 null 鍵也不允許 null 值。都是Java中用于實現對象的比較、排序的接口。
//Comparablepublic class Student implements Comparable{public int compareTo(Student another) {}}Collections.sort( studentList )//Comparatorpublic class Student{}class StudentComparator implements Comparator { public int compare(Student one, Student another) {}}Collections.sort( studentList , new StudentComparator());
腦圖地址: http://www.xmind.net/m/UPWK
參考: Difference between Set, List and Map in Java - Interview question Java集合干貨系列-集合總體大綱
新聞熱點
疑難解答