Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Last active December 19, 2015 17:19
Embed
What would you like to do?
Map<Integer, Long> map = people.stream()
.filter(p -> p.getAge() > 20)
.collect(
Collectors.groupingBy(Person::getAge),
Collectors.counting() // the downstream collector
);
Map<Integer, Set<String> map = people.stream()
.filter(p -> p.getAge() > 20)
.collect(
Collectors.groupingBy(
Person::getAge,
Collectors.mapping(
Person::getLastname,
Collectors.toCollection(TreeSet::new)
)
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment