常用iterate 方法
1 Map<Integer, String> m = new HashMap<Integer, String>(); 2 for(Map.Entry<Integer, String> entry : m.entrySet()){ 3 System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue()); 4 } 5 6 7 Iterator<Map.Entry<Integer, String>> iterator = m.entrySet().iterator(); 8 while(iterator.hasNext()){ 9 Map.Entry entry = iterator.next(); 10 System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue()); 11 }
1 for(Character key : hm.keySet()){ 2 System.out.println("Key: " + key + " Value: " + hm.get(key)); 3 }