Iterate Map in Java 8 using Stream API
In this code snippet, you will learn how to iterate a map in Java 8 using Stream API. You can convert your entry set to a stream and then iterate over it using forEach.
Advertisements
public void getValuesFromMap(Map<String, Integer> map) { map.entrySet().stream() // ... your filter or other chain methods here .forEach(e -> System.out.println(e.getKey() + ":" + e.getValue())); }