Map
|--hashtable: The underlying is a hash table data structure that cannot be stored as a null key null value. The collection is thread-synchronized. jdk1.0. Low efficiency.
|--hashmap: The underlying is a hash table data structure that allows NULL values and NULL keys, which are not synchronized. Replace Hashtable, jdk1.2. High efficiency.
|--treemap: The bottom layer is a two-fork tree data structure. Thread is out of sync. Can be used to sort the keys in the map collection.
It's like set.
In fact, the set bottom is the use of the map collection.
/*two ways to take out the map collection:1,set<k> KeySet: All the keys in the map are stored in the set collection. Because set has iterators. All the keys that can be iterated out are taken in accordance with the Get method. Gets the value corresponding to each key. The extraction principle of the Map collection: The Map collection is turned into a set set. is removed by an iterator. 2,set<map.entry<k,v>> EntrySet: The mapping relationship in the map collection is stored in the set set, and the data type of the relationship is: Map.entry En The try is actually a static internal interface in the map. Why should it be defined in the interior? Because only with the map collection, there is a key-value pair, there will be a key value of the mapping relationship. A relationship belongs to an internal thing in the map collection. And the object accesses the elements in the map collection directly. */ImportJava.util.*;classMapDemo2 { Public Static voidMain (string[] args) {Map<String,String> map =NewHashmap<string,string>(); Map.put ("Zhangsan2", "the"); Map.put ("Zhangsan3", "the"); Map.put ("Zhangsan1", "the"); Map.put ("", "Zhangsan4"); //takes the mapping relationship from the map collection out. Into the set set. Set<map.entry<string,string>> EntrySet =Map.entryset (); Iterator<Map.Entry<String,String>> it =Entryset.iterator (); while(It.hasnext ()) {Map.entry<String,String> me =It.next (); String Key=Me.getkey (); String value=Me.getvalue (); SYSTEM.OUT.PRINTLN (Key+":"+value); } /*first gets the set set of all keys for the map collection, KeySet (); set<string> KeySet = Map.keyset (); With the set set. To get its iterators. Iterator<string> it = Keyset.iterator (); while (It.hasnext ()) {String key = It.next (); A key can get its corresponding value through the Get method of the map collection. String value = Map.get (key); System.out.println ("Key:" +key+ ", Value:" +value); } */ }}/*Map.entry actually Entry is also an interface, which is an internal interface in the Map interface. Interface map{public static interface Entry {public abstract Object GetKey (); Public abstract Object GetValue (); }}class HashMap implements map{class Hahs implements Map.entry {public Object GetKey () {} public Ob Ject GetValue () {} }}*/
Understanding of Map Collections in Java