java loop a hash map code example
Example 1: how to iterate hashmap java
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
Example 2: java loop hashmap
map.forEach((k, v) -> {
System.out.format("key: %s, value: %d%n", k, v);
});