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