loop through a hashMap java code example
Example 1: java iterate through hashmap
for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
Example 2: 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 3: java loop hashmap
map.forEach((k, v) -> {
System.out.format("key: %s, value: %d%n", k, v);
});