Вы можете сделать это:
Map<Employee, List<Employee>> employeeMap = employeeList.stream()
.collect(groupingBy(Employee::getDepartment))
.values().stream()
.collect(
groupingBy(
(es) -> es.stream()
.max(Comparator.comparing(e -> e.getSalary())).get()
)
).entrySet().stream()
.collect(toMap(
Map.Entry::getKey,
e -> e.getValue().iterator().next()
));
Вывод:
{(Michael Reeves, 40, 45000.0, OPERATIONS)=[(James Elliot, 58, 24000.0, OPERATIONS), (Michael Reeves, 40, 45000.0, OPERATIONS)],
(Catherine Jones, 21, 18000.0, HR)=[(Catherine Jones, 21, 18000.0, HR)],
(Ethan Hardy, 65, 30000.0, LEGAL)=[(Harry Major, 26, 20000.0, LEGAL), (Ethan Hardy, 65, 30000.0, LEGAL)],
(Frank Anthony, 55, 32000.0, MARKETING)=[(Tom Jones, 45, 12000.0, MARKETING), (Nancy Smith, 22, 15000.0, MARKETING), (Frank Anthony, 55, 32000.0, MARKETING)]}
Ссылка на repl.it: https://repl.it/repls/CluelessAwesomeLevel#Main. java