1.直接遍历输出
for (Map.Entry<String, Integer> entry : hashMap.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); }
2.利用迭代器遍历输出
Set<Map.Entry<String, Integer>> set = hashMap.entrySet(); Iterator iterator = set.iterator(); while (iterator.hasNext()){ Map.Entry entry = (Map.Entry) iterator.next(); System.out.print(entry.getKey()+":"+entry.getValue()); }