Java容器总结

按数据结构主要有以下几类:

  • 内置容器:数组
  • 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 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值