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?
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?
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));
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));