Oracle
1Z0-809 · Question #256
1Z0-809 Question #256: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #256. The question stem and answer options stay visible for context.
Question
Given the definition of the Employee class:
class Employee {
String dept, name;
public Employee(String d, String n) {
dept = d;
name = n;
}
public String toString() {
return getDept() + ":" + getName();
}
public String getDept() { return dept; }
public String getName() { return name; }
}
And this code fragment:
List<Employee> emps = Arrays.asList(new Employee("sales", "Ada"),
new Employee("sales", "Bob"),
new Employee("hr", "Bob"),
new Employee("hr", "Eva"));
Stream<Employee> s = emps.stream()
.sorted(Comparator.comparing((Employee e) -> e.getDept())
.thenComparing((Employee e) -> e.getName()));
List<Employee> eSorted = s.collect(Collectors.toList());
System.out.println(eSorted);
What is the result?Options
- A[sales:Ada, hr:Bob, sales:Bob, hr:Eva]
- B[Ada:sales, Bob:sales, Bob:hr, Eva:hr]
- C[hr:Eva, hr:Bob, sales:Bob, sales:Ada]
- D[hr:Bob, hr:Eva, sales:Ada, sales:Bob]
Unlock 1Z0-809 to see the answer
You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.