Java集合容器总结

Java集合容器总结

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

你可能感兴趣的:(java集合)