Which code fragment, when inserted at line n1, sorts th…

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> 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?

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> 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?

A.
.sorted (Comparator.comparing(Emp::getfName).reserved().thenComparing(Emp::getlName))

B.
.sorted (Comparator.comparing(Emp::getfName).thenComparing(Emp::getlName))

C.
.map(Emp::getfName).sorted(Comparator.reserveOrder())

D.
.map(Emp::getfName).sorted(Comparator.reserveOrder().map
(Emp::getlName).reserved



Leave a Reply 5

Your email address will not be published. Required fields are marked *


smh

smh

anyone got any solution on this question. reserve should be reverse I guess.

DG

DG

Sure thing.
Should be A.