读[Collection接口和Map接口的主要实现类]小结

来源:互联网 发布:godaddy域名被转走 编辑:程序博客网 时间:2024/05/21 07:00

Collection 接口

List 接口

LinkedList  [异步]链表存储,引数据慢插入数据快   实现同步:List list = Collections.synchronizedList(new LinkedList(...));

ArrayList  [异步]类似数组存储,连续存储,引数据快插入数据慢   在插入前可以调用ensureCapacity方法来增加ArrayList的容量以提高插入效率。

Vector[同步]类似ArrayList

Stack继承Vector     五个独有方法:push   pop   peak    empty    search

  Set 接口(对象不能重复)

HashSet  能快速定位元素  通过HashCode找元素,确保A.equals(B)的同时A.HashCode()==B.HashCode()

TreeSet  按顺序存放,需要实现Comparator接口


Map 接口

TreeMap  键按顺序存储   独有方法:getFirstKey()  getLastKey()

HashTable [同步]key和value都非null   通过散列函数定位   确保A.equals(B)的同时A.HashCode()==B.HashCode()  

HashMap [异步] 允许null     可以通过Collections.synchronizedMap()创建同步Map

WeakHashMap  改进的HashMap,弱引用,当一个Key不再被外部引用将会被GC回收


0 0
原创粉丝点击