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);
D.
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.