nerdexam
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)
  • A
    78% (29)
  • B
    14% (5)
  • C
    3% (1)
  • D
    5% (2)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice