Java.until.Map,Set,List的资料整理
2008-01-05 09:59:10 来源:WEB开发网核心提示:1.CollecitonFramework(J2SDK1.4 )一般用途Class作方式2.Collection Framework(J2SDK 1.4)一般用途Class特色与食用范围比较Collections => Collection是所有List跟Set的始祖,List必须以特定次序来持有对象,Java.
1.CollecitonFramework(J2SDK1.4 )一般用途Class作方式
2.Collection Framework(J2SDK 1.4)一般用途Class特色与食用范围比较
Collections => Collection是所有List跟Set的始祖,List必须以特定次序来持有对象,Set无法拥有重复元素
ArrayList => 用Array实做的List,答应快速随机存取,相较于LinkedList 不适合拿来进行元素安插和移除动作
LinkedList => 提供最佳循序存取,适合安插和移除元素,随机存取动作比起ArrayList缓慢
HashSet => 是一种collection,但是只存放唯一值,是把搜寻时间看的很重要的set,用hash方式实作的set,故access time complexity = O(1)
TreeSet => 同上,但是存入的元素都会经过排列,所以速度比HashSet 慢一点
LinkedHashSet =>
Performance is likely to be just slightly below that of HashSet, due to the added eXPense of maintaining the linked list, with one exception: Iteration over a LinkedHashSet requires time PRoportional to the size of the set, regardless of its capacity. Iteration over a HashSet is likely to be more expensive, requiring time proportional to its capacity.
BitSet => 能够高效率的储存大量 [ 1 / 0 ] (开/关) 资料
HashMap => 用来取代HashTable,储存 (key/value) pairs
TreeMap => 储存 (key/value) pairs,会自动根据Key值排序
LinkedHashMap =>
Performance is likely to be just slightly below that of HashMap, due to the added expense of maintaining the linked list, with one exception: Iteration over the collection-views of a LinkedHashMap requires time proportional to the size of the map, regardless of its capacity. Iteration over a HashMap is likely to be more expensive, requiring time proportional to its capacity.
IdentityHashMap =>
This has better locality for large tables than does using separate arrays.) For many JRE implementations and Operation mixes, this class will yield better performance than HashMap (which uses chaining rather than linear-probing
WeakHashMap => 这个map中,由于每个Value仅存在一个实体,因而节省了储存空间,一但程序需要某个Value,便在map中搜寻既有的对象,并使用找到的那个对象(而非重新再造一个),由于这是一种节省储存空间的技巧,所以能够方便的让GC自动清理Key和Value,一但Key不在被使用,便会触发清理动作
容器简介
1.容器的分类
1.1.Collection:一组各自独立的元素,即其内的每个位置仅持有一个元素。
1)List:以元素安插的次序来放置元素,不会重新排列。
2)Set:不接爱重复元素,它会使用自己内部的一个排列机制
1.2.Map:一群成对的key-value对象,即所持有的是key-value pairs。
Map中不能有重复的key,它拥有自己的内部排列机制。
2.容器中的元素类型都为Object。从容器取得元素时,必须把它转换成原来的类型。
更多精彩
赞助商链接