java基礎總結之Hashtable

來源:互聯網
上載者:User

標籤:pre   tostring   keyset   同步   容量   eth   log   oid   負載   

package cn.wen.basic.test;import java.util.Enumeration;import java.util.Hashtable;import java.util.Set;import org.junit.Test;/* * HashTable和HashMap的主要區別就是一個支援同步一個不支援同步,但是就在單線程中的運行速度而言,HashMap更快 * 在java1.2版本之後 這個類改為實現Map介面。 * 如果不需要實現線程同步,建議使用HashMap,如果實現線程同步,建議使用ConCurrentHashMap代替HashTable */public class testHashTable {@Testpublic void testHashTableMethod(){Hashtable<String,String> ht=new Hashtable<String,String>();//構造一個新的並且為空白的Hashtable,並且預設容量為11和預設負載因子為0.75ht.put("1","001");ht.put("2","002");ht.put("ji", "jd");ht.put("ere2", "dfdfe");String one=ht.get("1");System.out.println(one);Enumeration<String> en=ht.keys();//擷取返回此散列鍵的枚舉Set<String> set=ht.keySet();//返回此map中鍵的set視圖。for(String key1:set){System.out.println(ht.get(key1));}while(en.hasMoreElements()){String key=en.nextElement();System.out.println(ht.get(key));}System.out.println(ht.toString());//以一組條目的形式返回此map的字串表示形式。並以acci碼錶中的","隔開}}

  

java基礎總結之Hashtable

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.