Oracle
1Z0-819 · Question #182
1Z0-819 Question #182: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-819 to reveal the answer and full explanation for question #182. The question stem and answer options stay visible for context.
Question
Given:
public class Employee {
private String name;
private String neighborhood;
private LocalDate birthday;
private int salary;
// ...getters and setters
}
and
List<Employee> roster = new ArrayList<>();
Map<String, Optional<Employee>> m = roster.stream()
// line 1
Which code fragment on line 1 makes the m map contain the employee with the highest salary for each neighborhood?
Options
- A.collect(Collectors.maxBy(Employee::getSalary, Collectors.groupingBy(Comparator.comparing(e -> e.getNeighborhood()))));
- B.collect(Collectors.groupingBy(Employee::getNeighborhood, Collectors.maxBy(Comparator.comparing(Employee::getSalary))));
- C.collect(Collectors.groupingBy(e -> e.getNeighborhood(), Collectors.maxBy((x, y) -> y.getSalary() - x.getSalary())));
- D.collect(Collectors.groupingBy(e -> e.getNeighborhood(), Collectors.collectingAndThen(Collectors.maxBy((x, y) -> x.getSalary() - y.getSalary()), Optional::get)));
Unlock 1Z0-819 to see the answer
You've previewed enough free 1Z0-819 questions. Unlock 1Z0-819 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.