1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 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?

Show Answer
Correct Answer: AB

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

4 comments
Sign in to comment
KMLAOption: C
Mar 1, 2023

c is the correct answer

TheOneAboveAllOption: A
Oct 16, 2023

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

cathDevOption: A
Apr 10, 2024

A is correct C is not correct Tested really

ASPushkinOption: A
May 22, 2024

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