Print HashMap Values with Stream api
17,388
Solution 1
Use entrySet()
(or values()
if that's what you need) instead of keySet()
:
Map<String, Double> missions = new HashMap<>();
missions.put("name", 1.0);
missions.put("name1", 2.0);
missions.entrySet().stream().forEach(e-> System.out.println(e));
Solution 2
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
Author by
Все Едно
Updated on June 28, 2022Comments
-
Все Едно almost 2 years
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?