- Collection
- List
- ArrayList
- LinkedList
- Set
- HashSet:基于HashMap
- LinkedHashSet
- List
- Map
- HashMap
- LinkedHashMap
- 继承HashMap,Entry中新增before和after属性,在newNode过程中额外处理,使得Iterator有序遍历
- Hashtable
- 与HashMap类似,线程同步,性能低
- TreeMap
- Comparator或Comparable,红黑树排序
- 同步
- 同步集合类:Hashtable、Vector
- 同步封装类:Collections.synchronizedMap()、Collections.synchronizedList()
- 整个集合加单锁,为防止ConcurrentModificationException,在迭代时将集合锁定,性能低
- ConcurrentModificationException
- iterator.next时,对list做写操作,引起modCount和expectedModCount不相等,抛ConcurrentModificationException
- iterator.remove是可以的,因其末尾有expectedModCount = modCount
- System.arraycopy
- C++和汇编的结合,提升数组复制效率
网友评论