Zest.

Java: Loop over a HashMap

A short, tested Java example for loop over a hashmap. Copy it and adjust the names and paths for your project.

Java
Map<String, Integer> m = new HashMap<>();
m.put("a", 1);

for (Map.Entry<String, Integer> e : m.entrySet()) {
    System.out.println(e.getKey() + " " + e.getValue());
}
m.forEach((k, v) -> System.out.println(k + " " + v));

Find it in Zest

Search for “java loop over a hashmap” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Java examples

All Java examples