Summary of Java Basics Hashtable

Source: Internet
Author: User

Package Cn.wen.basic.test;import Java.util.enumeration;import Java.util.hashtable;import java.util.Set;import The main difference between org.junit.test;/* * Hashtable and HashMap is that a support synchronization one does not support synchronization, but in the single-threaded run speed, hashmap faster * After the java1.2 version of this class to implement the map interface. * If you do not need to implement thread synchronization, we recommend using HashMap, if you implement thread synchronization, it is recommended to use CONCURRENTHASHMAP instead of Hashtable */public class Testhashtable {@Testpublic void Testhashtablemethod () {hashtable<string,string> ht=new hashtable<string,string> ();// Constructs a new and empty Hashtable, and the default capacity is 11 and the default load factor is 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 ();//Gets the enumeration that returns this hash key set<string> set=ht.keyset ();//Returns the set view of the key in this map. 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 ());//Returns a string representation of this map in the form of a set of entries. and separated by "," in the ACCI Code table}

  

Summary of Java Basics hashtable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.