Oracle
1Z0-819 · Question #93
Given: public class Employee { private String name; private String locality; / the constructor, getter and setter methods code goes here / } and: List<Employee> roster = new ArrayList<>(); int…
The correct answer is A. map(e -> e.getLocality()) .distinct().count(). See the full explanation below for the reasoning.
Question
Given:
public class Employee {
private String name;
private String locality;
/* the constructor, getter and setter methods code goes here */
}
and:
List<Employee> roster = new ArrayList<>();
int empCount = roster.stream().
/* insert code here */ // line 10
System.out.print(empCount);
Which code, when inserted on line 10, prints the number of unique localities from the roster list?
Options
- Amap(e -> e.getLocality()) .distinct().count();
- Bmap(e -> e.getLocality()) .collect(Collectors.toMap());
- Cmap(e -> e.getLocality()) .count();
- Ddistinct() .count();
How the community answered
(37 responses)- A78% (29)
- B14% (5)
- C3% (1)
- D5% (2)
Community Discussion
No community discussion yet for this question.