1 package Demo01; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 import java.util.Set; 6 7 public class test01 { 8 public static void main(String[] args) { 9 Map<String,String> a = new HashMap<String, String>(); 10 a.put("a", "1"); 11 a.put("b", "12"); 12 a.put("c", "13"); 13 a.put("a", "12"); 14 System.out.println (A); 15 // way: Get all the keys, then the value obtained according to the key 16 // Get all map key, all keys stored in a set Set, traversal set the set value to get the value of the get method using the Map . 17 set <String> Keys = a.keySet (); 18 is for (String Key: Keys) { . 19 System.out.println (Key + ":" + a.get (Key)); 20 is } 21 is @ way: direct access to all key-value pairs 22 // interface represents a key-value pair is the Entry 23 is // all keys stored in the Map set set to 24 // set storing a set of key-value pairs is 25 // external classes. class inner 26 Set<Map.Entry<String,String>> entrys=a.entrySet(); 27 for (Map.Entry<String, String> entry : entrys) { 28 System.out.println(entry.getKey()+":"+entry.getValue()); 29 } 30 } 31 32 33 34 35 36 37 38 39 40 41 }