Filter map and return list of keys
Collectors.toList()
does not take any argument, you need to map
it first:
eligibleStudents = studentMap.entrySet().stream()
.filter(a -> a.getValue().getAge() > 20)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
toList()
collector just creates a container to accumulate elements and takes no arguments. You need to do a mapping before it is collected. Here's how it looks.
List<String> eligibleStudents = studentMap.entrySet().stream()
.filter(a -> a.getValue().getAge() > 20)
.map(Map.Entry::getKey)
.collect(Collectors.toList());