Import Java. util. hashmap; import Java. util. iterator; import Java. util. map; public class mapdemo {public static void main (string [] ARGs) {Map <integer, string> map = new hashmap <integer, string> (); map. put (1, "Java programming ideas"); map. put (2, "a deep understanding of computer systems"); map. put (3, "computer network, top-down method"); map. put (4, "deep understanding of Java Virtual Machine specifications"); map. put (5, "Introduction to algorithms"); map. put (6, "programming Pearl"); // The first type: For (integer key: map. keyset () {system. out. println ("Key =" + key + ", value =" + map. get (key);} system. out. println ("========================================== ========== "); // The second type: It seems that such writing is rare for iterator <map. entry <integer, string> it = map. entryset (). iterator (); While (it. hasnext () {map. entry <integer, string> entry = it. next (); system. out. println ("Key =" + entry. getkey () + ", value =" + entry. getvalue ();} system. out. println ("========================================== ========== "); // method 3: Recommended, especially for (map. entry <integer, string> entry: map. entryset () {system. out. println ("Key =" + entry. getkey () + ", value =" + entry. getvalue ();} system. out. println ("========================================== ========== "); // type 4: Only valuesfor (string value: map. values () {system. out. println ("value =" + value );}}}