The main three methods:
1, KeySet (), gets the key of the map and returns the set view.
2. VALUES () Gets the value of the map.
3, EntrySet (). Recommended, because this method preserves the properties of key-value pairs.
Packagecd.itcast.runble;Importjava.util.Collection;ImportJava.util.HashMap;ImportJava.util.Iterator;ImportJava.util.Map;ImportJava.util.Map.Entry;ImportJava.util.Set;/*** Double-row set map, traverse * 1, KeySet (); * 2, values (); * 3, EntrySet (); Recommended Use *@authorAdministrator *ctrl+shift+o Quick Guide Package*/ Public classDemo5 { Public Static voidMain (string[] args) {Map<string, string> map =NewHashmap<string, string>(); Map.put ("Cheng Long", "Linfengjiao"); Map.put ("Jacky Lau Wei", "Yang Mi"); Map.put ("Deng Chao", "Empress"); /*1, the first method * set<string> MSet = Map.keyset (); Iterator<string> it = Mset.iterator (); while (It.hasnext ()) {System.out.println (Map.get (It.next ())); }*/ /*2. The second method * collection<string> values = map.values (); iterator<string> Iterator = Values.iterator (); while (Iterator.hasnext ()) {System.out.println (Iterator.next ()); }*/ /*3, recommended a third * set<entry<string,string>> Entrys = Map.entryset (); Iterator<entry<string,string>> it = Entrys.iterator (); while (It.hasnext ()) {entry<string,string> Entry = It.next (); System.out.println ("Key:" +entry.getkey () + "value:" +entry.getvalue ()); }*/ }}
Traversal of Map