Skip to content

Instantly share code, notes, and snippets.

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
You can’t perform that action at this time.