Java集合容器总结

Java集合容器总结。
<wbr style="line-height:25px">按数据结构主要有以下几类</wbr><wbr style="line-height:25px">:<br style="line-height:25px"><wbr style="line-height:25px"><span style="line-height:25px">1,内置容器:</span><span style="color:#000080; line-height:25px">数组</span><br style="line-height:25px"><wbr style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">2,list容器</wbr></span><wbr style="line-height:25px">:<span style="color:#000080; line-height:25px">Vetor,Stack,ArrayList,LinkedList,<br style="line-height:25px"> CopyOnWriteArrayList(1.5),AttributeList(1.5),RoleList(1.5),RoleUnresolvedList(1.5),<br style="line-height:25px"> ConcurrentLinkedQueue(1.5),ArrayBlockingQueue(1.5),LinkedBlockingQueue(1.5),<br style="line-height:25px"> PriorityQueue(1.5),PriorityBlockingQueue(1.5),SynchronousQueue(1.5)</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">3,set容器</wbr></span><wbr style="line-height:25px">:<span style="color:#000080; line-height:25px">HashSet(1.2),LinkedHashSet(1.4),TreeSet(1.2),<br style="line-height:25px"> CopyOnWriteArraySet(1.5),EnumSet(1.5),JobStateReasons。</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">4,map容器</wbr></span><wbr style="line-height:25px"><span style="color:#000080; line-height:25px">:Hashtable,HashMap(1.2),TreeMap(1.2),LinkedHashMap(1.4),WeakHashMap(1.2),<br style="line-height:25px"> IdentityHashMap(1.4),ConcurrentMap(1.5),concurrentHashMap(1.5)。</span><br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff00ff; line-height:25px">Set</span><span style="color:#003366; line-height:25px">接口继承Collection,但不允许重复,使用自己内部的一个排列机制。</span><br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">List</span><span style="color:#003366; line-height:25px">接口继承Collection,允许重复,以元素安插的次序来放置元素,不会重新排列。</span><br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">Map</span><span style="color:#003366; line-height:25px">接口是一组成对的键-值对象,即所持有的是key-valuepairs。Map中不能有重复的key。拥有自己的内部排列机制<wbr style="line-height:25px">。</wbr></span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">按新旧主要有以下几类</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"> Java1.2前的容器:<span style="color:#000080; line-height:25px">Vector,Stack,Hashtable。</span><br style="line-height:25px"> Java1.2的容器:<span style="color:#000080; line-height:25px">HashSet,TreeSet,HashMap,TreeMap,WeakHashMap</span><br style="line-height:25px"> Java1.4的容器:<span style="color:#000080; line-height:25px">LinkedHashSet,LinkedHashMap,IdentityHashMap,ConcurrentMap,concurrentHashMap</span><br style="line-height:25px"> java1.5新增:<span style="color:#000080; line-height:25px">CopyOnWriteArrayList,AttributeList,RoleList,RoleUnresolvedList,<br style="line-height:25px"> ConcurrentLinkedQueue,ArrayBlockingQueue,LinkedBlockingQueue,PriorityBlockingQueue<br style="line-height:25px"> ArrayBlockingQueue,CopyOnWriteArraySet,EnumSet,</span><br style="line-height:25px"> 未知:JobStateReasons<br style="line-height:25px"><span style="color:#ff6600; line-height:25px"><wbr style="line-height:25px">按线程安全主要有以下几类<wbr style="line-height:25px">:</wbr></wbr></span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">线程安全</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"> 一,<span style="line-height:25px"><wbr style="line-height:25px">使用锁</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"> 1.1、<span style="line-height:25px"><wbr style="line-height:25px">完全不支持并发</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:V<span style="color:#000080; line-height:25px">etor,Stack,CopyOnWriteArrayList,ArrayBlockingQueue,<br style="line-height:25px"> LinkedBlockingQueue,PriorityBlockingQueue,SynchronousQueue</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:<span style="color:#000080; line-height:25px">CopyOnWriteArraySet</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:<span style="color:#0000ff; line-height:25px">Hashtable</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">部分支持并发</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"> l<span style="color:#993300; line-height:25px">ist容器</span>:无<br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:无<br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:<span style="color:#000080; line-height:25px">concurrentHashMap</span><br style="line-height:25px"> 2.2、<span style="line-height:25px"><wbr style="line-height:25px">使用非阻塞算法</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"> list容器:ConcurrentLinkedQueue<br style="line-height:25px"> set容器:无<br style="line-height:25px"> map容器:无<br style="line-height:25px"> 二,<span style="line-height:25px"><wbr style="line-height:25px">非线程安全</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">ArrayList,LinkedList,AttributeList,RoleList,RoleUnresolvedList,PriorityQueue</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:<span style="color:#000080; line-height:25px">HashSet,TreeSet,LinkedHashSet,EnumSet</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:<span style="color:#000080; line-height:25px">HashMap,TreeMap,LinkedHashMap,WeakHashMap,IdentityHashMap,EnumMap</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">按遍历安全主要有以下几类</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"> 一,<span style="line-height:25px"><wbr style="line-height:25px">遍历安全</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">可并发遍历</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">CopyOnWriteArrayList,ConcurrentLinkedQueue</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:<span style="color:#000080; line-height:25px">CopyOnWriteArraySet,EnumSet,EnumMap</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:无<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">不可并发遍历</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">Vetor,Stack,Hashtable,ArrayBlockingQueue,</span><br style="line-height:25px"><span style="color:#000080; line-height:25px">LinkedBlockingQueue,PriorityBlockingQueue,SynchronousQueue</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:无<br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:<span style="color:#000080; line-height:25px">Hashtable,concurrentHashMap</span><br style="line-height:25px"> 注意1:<span style="color:#0000ff; line-height:25px">concurrentHashMap</span>迭代器它们不会抛出ConcurrentModificationException。不过,迭代器被设计成每次仅由一个线程使用。<br style="line-height:25px"> 二,<span style="line-height:25px"><wbr style="line-height:25px">遍历不安全</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">会抛异常</wbr></span><wbr style="line-height:25px"><span style="color:#0000ff; line-height:25px">ConcurrentModificationException</span>:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">ArrayList,LinkedList,AttributeList,RoleList,RoleUnresolvedList</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:<span style="color:#000080; line-height:25px">HashSet,TreeSet,TreeSet,LinkedHashSet</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:<span style="color:#000080; line-height:25px">HashMap,TreeMap,LinkedHashMap,WeakHashMap,IdentityHashMap</span> <div style="line-height:25px"> <span style="color:#000080; line-height:25px"><br style="line-height:25px"></span><span style="line-height:25px"><wbr style="line-height:25px">注意1</wbr></span><wbr style="line-height:25px">:<span style="color:#99cc00; line-height:22px">EnumSet</span><span style="color:#808000; line-height:22px">,</span><span style="line-height:22px">和</span><span style="color:#808000; line-height:22px">EnumMap</span>返回的迭代器是弱一致的:它们不会抛出ConcurrentModificationException,</wbr> </div> <div style="line-height:25px">也不一定显示在迭代进行时发生的任何映射修改。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#ff6600; line-height:25px">按是否有序性分类</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:25px">存储数据简单有序</span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">ConcurrentLinkedQueue(1.5),ArrayBlockingQueue(1.5),LinkedBlockingQueue(1.5),<br style="line-height:25px"> SynchronousQueue(1.5)</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:<span style="color:#000080; line-height:25px">TreeSet(1.2).(他们实现了set接口),<br style="line-height:25px"> CopyOnWriteArraySet(1.5),EnumSet(1.5),JobStateReasons。<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">map容器</span><span style="color:#000080; line-height:25px">:TreeMap(1.2),LinkedHashMap(1.4)。</span><br style="line-height:25px"><span style="line-height:25px">存储数据有特定序</span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">Stack,Vetor,ArrayList,LinkedList,CopyOnWriteArrayList(1.5),AttributeList(1.5),RoleList(1.5),RoleUnresolvedList(1.5)</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:无<br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:无<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">遍历无序但移除有序</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">PriorityQueue(1.5),PriorityBlockingQueue(1.5)</span><br style="line-height:25px"> set容器:无<br style="line-height:25px"> map容器:无<br style="line-height:25px"><span style="line-height:25px">无论如何<wbr style="line-height:25px">都无序</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:无<br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span>:<span style="color:#000080; line-height:25px">HashSet(1.2),LinkedHashSet(1.4)</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span>:<span style="color:#000080; line-height:25px">Hashtable,HashMap(1.2),WeakHashMap(1.2),IdentityHashMap(1.4),<br style="line-height:25px"> ConcurrentMap(1.5),concurrentHashMap(1.5)</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">可以按自然顺序(参见Comparable)或比较器进行排序的有</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#993300; line-height:25px">list容器</span>:<span style="color:#000080; line-height:25px">PriorityQueue(1.5),PriorityBlockingQueue</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">set容器</span><span style="color:#000080; line-height:25px">:TreeSet(1.2)</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">map容器</span><span style="color:#000080; line-height:25px">:TreeMap(1.2)</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">实现了RandomAccess接口的有</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#003366; line-height:25px"></span><span style="color:#ff9900; line-height:25px">ArrayList,AttributeList,CopyOnWriteArrayList,RoleList,RoleUnresolvedList,Stack,Vector<br style="line-height:25px"> RandomAccess</span><span style="color:#003366; line-height:25px">接口是List实现所使用的标记接口,用来表明其支持快速(通常是固定时间)随机访问。此接口的主要目的是允许一般的算法更改其行为,从而在将其应用到随机或连续访问列表时能提供良好的性能。</span><br style="line-height:25px"><span style="color:#003366; line-height:25px">在对</span><span style="color:#ff00ff; line-height:25px">List</span><span style="color:#003366; line-height:25px">特别的遍历算法中,要尽量来判断是属于</span><span style="color:#ff9900; line-height:25px">RandomAccess</span><span style="color:#003366; line-height:25px">(如ArrayList)还是</span><span style="color:#ff9900; line-height:25px">SequenceAccess</span><span style="color:#003366; line-height:25px">(如LinkedList),</span><br style="line-height:25px"><span style="color:#003366; line-height:25px">因为适合</span><span style="color:#ff9900; line-height:25px">RandomAccessList</span><span style="color:#003366; line-height:25px">的遍历算法,用在</span><span style="color:#ff9900; line-height:25px">SequenceAccessList</span><span style="color:#003366; line-height:25px">上就差别很大,</span><br style="line-height:25px"><span style="color:#003366; line-height:25px">即对于实现了RandomAccess接口的类实例而言,此循环</span><br style="line-height:25px"><span style="color:#0000ff; line-height:25px">for(inti=0,i&lt;list.size();i++)<br style="line-height:25px"> list.get(i);</span><br style="line-height:25px"> 的运行速度要快于以下循环:<br style="line-height:25px"><span style="color:#0000ff; line-height:25px">for(Iteratori=list.iterator();i.hasNext();)<br style="line-height:25px"> i.next();</span><br style="line-height:25px"> 关于RandomAccess接口更多详细可以参考<wbr style="line-height:25px">《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/171040579201071202953872/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">随机访问RandomAccess</a></strong>》<wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">容量不能自动扩展的有:</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#0000ff; line-height:25px">ArrayBlockingQueue</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> </div> </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值