作者:YouChuang
本文主要介绍Java集合的总体架构。
JDK中常用的jar包和对应的库
Java的集合工具包架构图
主要是Collection接口和Map接口
Collection
一个高度抽象的接口
The JDK does not provide any direct implementations of this interface: it provides implementations of more specific subinterfaces like Set and List. This interface is typically used to pass collections around and manipulate them where maximum generality is desired.
List
有序队列,索引+元素,索引从0开始
实现类
LinkedList
ArrayList
Vector
Stack
Set
不允许有重复元素的集合
实现类
HashSet,依赖于HashMap,并由HashMap实现,因为方法的实现都是调用的HashMap的方法
private transient HashMap<E,Object> map;
public HashSet() {
map = new HashMap<>();
}
public int size() {
return map.size();
}
TreeSet,依赖于TreeMap,由TreeMap实现
Map
映射接口,K-V键值对
AbstractMap为抽象类,实现了Map中的大多数API,
HashMap、TreeMap、WeakHashMap继承于AbstractMap
HashTable继承Dictionary,实现Map接口
Iterator
遍历工具的集合,Collection依赖于Iterator,因为Collection的实现类都要实现Iterator()函数来返回一个Iterator对象
ListIterator专门遍历List
Enumeration
遍历集合,只能在HashTable、Vector、Stack中使用
Arrays和Collections
操作数组和集合的两个工具类
参考:
http://www.cnblogs.com/skywang12345/p/3308498.html
http://blog.csdn.net/ns_code/article/details/35564663
JDK1.8.8_20