Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 117

Given:

and

Which code fragment on line 1 makes the m map contain the employee with the highest salary for each neighborhood?

    Correct Answer: A

    To create a map that contains the employee with the highest salary for each neighborhood, the correct code fragment should use the Collectors.groupingBy method to group employees by neighborhood, and within each group, collect the employee with the highest salary. The Collectors.groupingBy method creates a map where the key is the neighborhood and the value is the optional employee who has the maximum salary within that neighborhood. This is done using Collectors.maxBy with a Comparator that compares employees by salary. Option A correctly implements this logic.

Discussion
ASPushkinOption: A

answer: A B,D Fail there is no Collectors.maxBy with two paramenets C FAILED sorted in descending order

cathDevOption: A

A is correct C is not correct Tested really

TheOneAboveAllOption: A

A tested. because it's asc sort default C is sort desc

KMLAOption: C

c is the correct answer