Print HashMap Values with Stream api

Viewed 21130
HashMap<String, Double> missions = new HashMap<>();
missions.put("name", 1.0);
missions.put("name1", 2.0);
missions.keySet().stream().forEach(el-> System.out.println(el));

This prints only the keys, how do I print the map's values instead?

3 Answers
HashMap<String, Double> missions = new HashMap<>();
missions.put("name", 1.0);
missions.put("name1", 2.0);
missions.entrySet().forEach(System.out::println);

Output:

name=1.0
name1=2.0
// Stores the values in a list which can later used

missions.values().stream().collect(Collectors.toList());

or

//print it to standard op

missions.values().forEach(val -> System.out.println(val));
Related