Skip to content

Instantly share code, notes, and snippets.

@theboreddev
Created July 18, 2020 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save theboreddev/d8f8ee3a980b92eff66c95331c9d1da0 to your computer and use it in GitHub Desktop.
Save theboreddev/d8f8ee3a980b92eff66c95331c9d1da0 to your computer and use it in GitHub Desktop.
groupBySex
final Collection<Employee> employees = List.of(
new Employee("Karen Smith", 51200.0, 29, Employee.Sex.FEMALE),
new Employee("John Smith", 24000.0, 32, Employee.Sex.MALE),
new Employee("Anthony Jackson", 44000.0, 33, Employee.Sex.MALE),
new Employee("Alyson Palmer", 34320.0, 36, Employee.Sex.FEMALE),
new Employee("Jessica Sanders", 64320.0, 34, Employee.Sex.FEMALE)
);
final Map<Employee.Sex, List<Employee>> employeesBySex = employees.stream()
.collect(groupingBy(Employee::getSex));
System.out.println(employeesBySex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment