1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 87


Given:

What is the result?

Show Answer
Correct Answer: C

The code creates an array of cat names and then adds those names to an ArrayList. It sorts the ArrayList in descending order using the lambda expression `(var a, var b) -> -a.compareTo(b)`, where the minus sign reverses the natural order of comparison. Finally, it prints each element of the sorted list. The correct result is the cat names in descending alphabetical order: sphynx, oxicat, laperm, korat, bengal, abyssinian.

Discussion

7 comments
Sign in to comment
StavokOption: C
Jun 7, 2023

C is correct TESTED

eldonivanOption: C
Aug 18, 2023

The default sort order is ascending. The line -a.compareTo(b) changes the order to descending. The answer is: C

tmuralimanoharOption: C
Jun 29, 2023

Answer:C

OmnisumemOption: C
Sep 12, 2023

Tested: C.

SampsOption: C
Dec 28, 2023

C is correct

mendjijetOption: C
Feb 9, 2024

C is corrrect the sort is inversed -a.compareTo(b)

ASPushkinOption: C
Jul 1, 2024

interesting thing : var cats = new ArrayList<>(Arrays.asList(catNames)); Diamond Operator - compiler's type inference feature determines the most suitable constructor declaration that matches the invocation. This is not a row type.