Oracle
1Z0-809 · Question #256
Given the definition of the Employee class: ``java class Employee { String dept, name; public Employee(String d, String n) { dept = d; name = n; } public String toString() { return getDept() + ":" +…
The correct answer is D. [hr:Bob, hr:Eva, sales:Ada, sales:Bob]. You've hit your session limit · resets 5:20pm (America/New_York)
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]
How the community answered
(35 responses)- A14% (5)
- B6% (2)
- C3% (1)
- D77% (27)
Explanation
You've hit your session limit · resets 5:20pm (America/New_York)
Community Discussion
No community discussion yet for this question.