Practice ยท 1 of 3
Compose Comparators
Work with records inside Solution:
- record Employee(String name, String dept, int salary)
- static List<String> topPaidByDept(List<Employee> staff, int n):
group employees by dept, sort each group by salary DESCENDING (ties by
name ASCENDING), and return dept + ":" + name for the top n of each
group, with depts in alphabetical order.
Use Comparator.comparing/thenComparing โ no anonymous classes.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Collections Lab