intermediateJava 8 & Streams80 of 436
Given an Employee list, group employees by department and find the employee with the highest salary in each department
Tests whether you reach for Collectors.groupingBy(Employee::getDepartment, Collectors.maxBy(Comparator.comparing(Employee::getSalary))) -- a downstream collector nested inside groupingBy -- rather than grouping first and then iterating each group manually to find the max.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a responseNext Step
←PreviousContinue to Why do we need async and await? What happens when you call an asynchronous API? Difference between async programming and multithreading?→
← Back to all Core Java questions