ProgrammingModerateProduct-company placement · Java

What is printed?

What is printed?
long n = Stream.of(List.of(1, 2), List.of(2, 3))
               .flatMap(List::stream).distinct().count();
System.out.print(n);
  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 1

Correct answer: B. 3

flatMap turns the two lists into one stream 1, 2, 2, 3; distinct removes the repeated 2, leaving 3 elements.

More OOP with C++ and Java questions

Exams that ask this topic