一.概覽
容器主要包括Collection和Map兩種,Collection存儲着對象的集合,Map存儲着鍵值對的映射。
Collection(interface)
Set(繼承,接口)
SortedSet(繼承,interface,)
TreeSet(實現)
HashSet(實現)
LinkedHashSet(實現)
List(繼承,接口)
ArrayList(實現)
Vector(實現,線程安全的,基本廢棄,過時)
LinkedList(有序,同時實現Queue)
Queue(繼承,,接口,隊列)
PriorityQueue(實現)
LinkedList(有序,同時實現List)
1.Set
- TreeSet:基於紅黑樹實現,支持有序性,效率不如HashSet,
- HashSet:基於哈希表實現,支持快速查找,不支持有序性操作,沒有順序,
- LinkedHashSet:具有HashSet的查找效率,並且有順序
2.List
- ArrayList:基於動態數組實現,支持隨機訪問
- Vector:類似ArrayList,線程安全
- LinkedList:雙向鏈表實現,智能順序訪問,能快速插入和刪除元素
3.Queue(不常用)
- LinkedList:可以用來實現雙向隊列。
- PriorityQueue:基於堆結構實現,用來實現優先隊列
Map(interface)
SortedMap(interface,繼承)
TreeMap(實現)
HashTable(過時,實現)
LinkedHashMap(實現)
HashMap(實現)
- TreeMap:基於紅黑樹實現(沒用過).
- HashMap:基於哈希表實現(最常用)
- HashTable:類似HashMap,線程安全,遺留類,可以使用ConcurrentHashMap來支持線程安全,用了分段鎖,效率更高
- LinkedHashMap:雙向鏈表來維護元素的順序,