1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Map<String, Integer> map = new HashMap<>(); map.put("张三", 20); map.put("李四", 21); map.put("王五", 22);
Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
Iterator<Map.Entry<String, Integer>> it = entrySet.iterator(); while(it.hasNext()) { Map.Entry<String, Integer> en = it.next(); String key = en.getKey(); Integer value = en.getValue(); System.out.println(key +" = " + value); } System.out.println("--------------"); for (Map.Entry<String, Integer> entry : entrySet) { System.out.println(entry.getKey() + "=" + entry.getValue()); }
|