国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
java集合map,set,list區(qū)別_CP規(guī)則
java集合map,set,list區(qū)別 作者:struggle  來源于:JAVA綜合網  發(fā)布時間:2007-10-11 22:14:11
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,會自動根據(jù)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僅存在一個實體,因而節(jié)省了儲存空間,一但程式需要某個Value,便在map中搜尋既有的物件,並使用找到的那個物件(而非重新再造一個),由於這是一種節(jié)省儲存空間的技巧,所以能夠方便的讓GC自動清理Key和Value,一但Key不在被使用,便會觸發(fā)清理動作
--------------------------------------------------------------------------------
容器簡介
1. 容器的分類
1.1. Collection:一組各自獨立的元素,即其內的每個位置僅持有一個元素。
1) List:以元素安插的次序來放置元素,不會重新排列。
2) Set:不接愛重復元素,它會使用自己內部的一個排列機制
1.2. Map:一群成對的key-value對象,即所持有的是key-value pairs。
Map中不能有重復的key,它擁有自己的內部排列機制。
2. 容器中的元素類型都為Object。從容器取得元素時,必須把它轉換成原來的類型。
看了下面的這個就更容易明白了
寫一段代碼,遍歷一個List中的元素
List、Map、Set三個接口,存取元素時,各有什么特點?
import java.util.*;
public class Test
{
public static void main(String [] arge)
{
List list = new ArrayList();
list.add(0, "a");
list.add(1, "b");
list.add(2, "c");
list.add(3, "d");
while(Iterator it = list.iterator();it.hasNext())
{
Object element = it.next();
System.out.println (element);
}
}
}
List、Map、Set
List 通過下標來存取 和值來存取
Map 鍵值對應來存取
set 存取元素是無序的
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Java中的Set,List,Map的區(qū)別
java中Map,List與Set的區(qū)別
Java集合源碼剖析之Java集合框架
《Java面向對象程序設計》10 Java集合寫字字帖
Java面試手冊:集合框架
java集合框架
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服