Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Last active December 19, 2015 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeaholicguy/e7d91308f8f6326ac652 to your computer and use it in GitHub Desktop.
Save codeaholicguy/e7d91308f8f6326ac652 to your computer and use it in GitHub Desktop.
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