1 Map<String,String> map = new HashMap<String,String>(); 2 map.put("shandong","jinan"); 3 map.put("shanxi","xian"); 4 map.put("jiangsu", "nanjing"); 5 System.out.println("Method 1"); 6 for(Map.Entry<String, String> entry:map.entrySet()) 7 { 8 System.out.println(entry.getKey() + "----->" + entry.getValue()); 9 } 10 11 Set set = map.entrySet(); 12 Iterator it = set.iterator(); 13 System.out.println("Method 2"); 14 while(it.hasNext()) 15 { 16 Map.Entry<String, String> entry1 = (Map.Entry<String, String>)it.next(); 17 System.out.println(entry1.getKey() + "----->" + entry1.getValue()); 18 }
时间: 2024-10-08 09:47:10