HashTable HashMap HashSet區別(java) [From 愛做飯的小瑩子]

來源:互聯網
上載者:User

標籤:

Hashtable:

 1. key和value都不許有null值

 2. 使用enumeration遍曆

 3. 同步的,每次只有一個線程能夠訪問

 4. 在java中Hashtable是H大寫,t小寫,而HashMap是H大寫,M大寫

 

HashMap:

 1. key和value可以有null值

 2. 使用iterator遍曆

 3. 未同步的,多線程場合要手動同步HashMap

 

 HashSet

 1. 底層調用HashMap

 2. 不允許有重複值

 

 常用Java操作:

 

 1 Hashtable<Integer, Integer> ht=new Hashtable<Integer, Integer>(); 2         ht.put(key, value); 3         ht.containsKey(key); 4         ht.containsValue(value); 5         ht.remove(key); 6         ht.remove(key, value);  7  8 HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>(); 9         hm.put(key, value);10         hm.containsKey(key);11         hm.containsValue(value);12         hm.remove(key);13         hm.remove(key, value);14         15 HashSet<Integer> hs = new HashSet<Integer>();16         hs.add(e);17         hs.contains(o);18         hs.remove(o);

 

Reference:

http://www.cnblogs.com/springfor/p/3859628.html

http://blog.sina.com.cn/s/blog_4586764e0100ivup.html

http://www.blogjava.net/fisher/archive/2006/12/13/87398.html

http://blog.csdn.net/wl_ldy/article/details/5941770

http://www.pakzilla.com/2009/08/24/hashmap-vs-hashtable-vs-hashset/

HashTable HashMap HashSet區別(java) [From 愛做飯的小瑩子]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.