Map<Integer, String> map = new HashMap<Integer, String>(); map.put(1, "dog"); map.put(2, "tiger"); //方式1,利用keySet方法的迭代器 for (Iterator<Integer> it=map.keySet().iterator();it.hasNext();){ Integer key = it.next(); String value = map.get(key); System.out.println(key+":"+value); } //方式2,利用entrySet方法的迭代器 for (Iterator<Map.Entry<Integer, String>> it=map.entrySet().iterator();it.hasNext();){ Map.Entry<Integer, String> me = it.next(); Integer key = me.getKey(); String value = me.getValue(); System.out.println(key+":"+value); }