按数据结构主要有以下几类:
- 内置容器:数组
- list容器:Vetor,Stack,ArrayList,LinkedList,CopyOnWriteArrayList,AttributeList,RoleList,RoleUnresolvedList,ConcurrentLinkedQueue,ArrayBlockingQueue,LinkedBlockingQueue,PriorityQueue,PriorityBlockingQueue,SynchronousQueue
- set容器:HashSet,LinkedHashSet,TreeSet,CopyOnWriteArraySet,EnumSet,JobStateReasons
- map容器:Hashtable,HashMap,TreeMap,LinkedHashMap,WeakHashMap,IdentityHashMap,ConcurrentMap,concurrentHashMap
特点:
Set 接口继承 Collection,但不允许重复,使用自己内部的一个排列机制。
List 接口继承 Collection,允许重复,以元素安插的次序来放置元素,不会重新排列。
Map接口是一组成对的键-值对象,即所持有的是key-value pairs。Map中不能有重复的key。拥有自己的内部排列机制。
按线程安全主要有以下几类:
线程安全
使用锁:
- 完全不支持并发:
list容器:Vetor,Stack,CopyOnWriteArrayList,ArrayBlockingQueue,LinkedBlockingQueue,PriorityBlockingQueue,SynchronousQueue
set容器:CopyOnWriteArraySet
map容器:Hashtable
- 部分支持并发:
list容器:无
set容器:无
map容器:concurrentHashMap
使用非阻塞算法:
list容器:ConcurrentLinkedQueue
set容器:无
map容器:无
非线程安全
list容器:ArrayList,LinkedList,AttributeList,RoleList,RoleUnresolvedList,PriorityQueue
set容器:HashSet,TreeSet,LinkedHashSet,EnumSet
map容器:HashMap,TreeMap,LinkedHashMap,WeakHashMap,IdentityHashMap,EnumMap
按遍历安全主要有以下几类:
遍历安全:
可并发遍历:
list容器:CopyOnWriteArrayList,ConcurrentLinkedQueue
set容器:CopyOnWriteArraySet,EnumSet,EnumMap
map容器:无
不可并发遍历:
list容器:Vetor,Stack,Hashtable,ArrayBlockingQueue,LinkedBlockingQueue,PriorityBlockingQueue,SynchronousQueue
set容器:无
map容器:Hashtable,concurrentHashMap
注意:concurrentHashMap迭代器它们不会抛出ConcurrentModificationException。不过,迭代器被设计成每次仅由一个线程使用。
遍历不安全:
会抛异常ConcurrentModificationException:
list容器:ArrayList,LinkedList,AttributeList,RoleList,RoleUnresolvedList
set容器:HashSet,TreeSet,TreeSet,LinkedHashSet
map容器:HashMap,TreeMap,LinkedHashMap,WeakHashMap,IdentityHashMap
注意1:EnumSet和EnumMap返回的迭代器是弱一致 的:它们不会抛出 ConcurrentModificationException,也不一定显示在迭代进行时发生的任何映射修改。
按是否有序性分类
- 存储数据简单有序:
list容器:ConcurrentLinkedQueue,ArrayBlockingQueue,LinkedBlockingQueue, SynchronousQueue
set容器:TreeSet(实现了set接口),CopyOnWriteArraySet,EnumSet,JobStateReasons
map容器:TreeMap,LinkedHashMap
- 存储数据有特定序:
list容器:Stack,Vetor,ArrayList,LinkedList,CopyOnWriteArrayList,AttributeList,RoleList,RoleUnresolvedList
set容器:无
map容器:无
- 遍历无序但移除有序:
list容器:PriorityQueue,PriorityBlockingQueue
set容器:无
map容器:无
- 无论如何都无序:
list容器:无
set容器:HashSet,LinkedHashSet
map容器:Hashtable,HashMap,WeakHashMap,IdentityHashMap,ConcurrentMap,concurrentHashMap
- 可以按自然顺序(参见 Comparable)或比较进行排序的有:
list容器:PriorityQueue,PriorityBlockingQueue
set容器:TreeSet
map容器:TreeMap
队列是否有界
有界队列:ArrayBlockingQueue,LinkedBlockingQueue(Integer.MAX_VALUE),SynchronousQueue
无界队列:ConcurrentLinkedQueue ,PriorityBlockingQueue ,DelayedQueue ,LinkedTransferQueue