hi, today we introduce the new method to traverse over the Map object with java 8.

1. construct a Map object

private static Map<String,String> constructMap() {
        return new HashMap<String,String>() {
            {
                put("k1","v1");
                put("k2","v2");
                put("k3","v3");
            }
        };
    }

2. Iterate over the map with stream and for-each

map.keySet().stream().forEach(k-> System.out.println(k+"-->"+map.get(k)));

You can find that java 8 stream and forEach is very easy to use and understand.

You can find more java 8 documents here: