Oracle
1Z0-819 · Question #64
Given public class Employee { private String name; private LocalDate birthday; // the constructors, getters, and setters methods go here } and List<Employee> roster = new ArrayList<>(); //…
The correct answer is B. .collect(Collectors.toCollection(TreeSet::new)). See the full explanation below for the reasoning.
Question
Given
public class Employee {
private String name;
private LocalDate birthday;
// the constructors, getters, and setters methods go here
}
and
List<Employee> roster = new ArrayList<>();
// ...
Predicate<Employee> p = (Employee e) -> e.getBirthday().
isBefore(IsoChronology. INSTANCE.date(1989, 1, 1));
Set<String> s1 = roster.stream()
. filter(p)
Which code fragment on line 1 makes the s1 set contain the names of all employees born before January 1, 1989?
Options
- A.collect(Collectors.partitioningBy(y)) .get(true) .stream() .map(Employee::getName)
- B.collect(Collectors.toCollection(TreeSet::new));
- C.collect(Collectors.partitioningBy(y)) .get(false) .map(Employee::getName) .collect(Collectors.toSet());
- D.collect(Collectors.partitioningBy(y, Collectors.mapping( Employee::getName, Collectors.toSet()))).
How the community answered
(39 responses)- A3% (1)
- B74% (29)
- C15% (6)
- D8% (3)
Community Discussion
No community discussion yet for this question.