Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 26

Given:

public class Emp {

String fName;

String lName;

public Emp (String fn, String ln) {

fName = fn;

lName = ln;

}

public String getfName() { return fName; }

public String getlName() { return lName; }

}

and the code fragment:

List emp = Arrays.asList (

new Emp ("John", "Smith"),

new Emp ("Peter", "Sam"),

new Emp ("Thomas", "Wale"));

emp.stream()

//line n1

.collect(Collectors.toList());

Which code fragment, when inserted at line n1, sorts the employees list in descending order of fName and then ascending order of lName?

    Correct Answer: A

    To sort the employees list in descending order of fName and then ascending order of lName, the correct code fragment should use Comparator.comparing with reversed for fName and thenComparing for lName. The correct option is `.sorted(Comparator.comparing(Emp::getfName).reversed().thenComparing(Emp::getlName))`.

Discussion
pul26Option: A

The correct answer is A. fName requested descending order. it's order should be reversed

chichikimOption: A

reserved() ===> reversed() The correct answer is A.

ThientvseOption: A

A, Checked

asdfjhfgjuaDCVOption: A

A is the correct answer.

steefaandOption: A

Answer is A, just replace reserved with reversed. First name is sorted in descending order and then last name in ascending.

r1muka5Option: A

Correct answer is A.

OhayouOption: A

checked

WilsonKKerllOption: A

Answer is A........