Java OCA OCP Practice Question 1737

Question

What does the following output?

Set<String> set = new HashSet<>();
set.add("A");
List<String> list = new LinkedList<>();
Deque<String> queue = new ArrayDeque<>();
queue.push("B");

Stream.of(set, list, queue)
   .flatMap(x -> x)
   .forEach(System.out::print);
  • A. [A][B]
  • B. AB
  • C. None of the above
  • D. The code does not compile.


D.

Note

The flatMap() method works with streams rather than collections.

The code does not compile because the x is not a stream, making Option D correct.

If this was fixed, Option B would be the answer.




PreviousNext

Related