1. for-each + entrySet()


for (Map.Entry<String, Integer> entry : map1.entrySet()) {
    System.out.print("key = " + entry.getKey());
    System.out.println(", value = " + entry.getValue());
}

2. lambda表达式


map.forEach((key, value)->{
    System.out.print("key = " + key);
    System.out.println(", value = " + value);
});

3. stream流


map.entrySet().stream().forEach((Map.Entry<String, Integer> entry) -> {
    System.out.print("key = " + entry.getKey());
    System.out.println(", value = " + entry.getValue());
});