Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.