Java 8 lambdas group list into map
It seems that the simple groupingBy
variant is what you need :
Map<String, List<Pojo>> map = pojos.stream().collect(Collectors.groupingBy(Pojo::getKey));
Also, if you wanted to return a similar map but instead of whole Pojo you wanted the map's values be some property of the Pojo, you would do like that:
Map<String, List<String>> map = pojos.stream()
.collect(
Collectors.groupingBy(
Employee::getKey, Collectors.mapping(
Pojo::getSomeStringProperty, Collectors.toList())));