What is the result of the following?.
Set<Integer> dice = new TreeSet<>();
dice.add(6);
dice.add(6);
dice.add(4);
dice.stream().filter(n -> n != 4).forEach(System.out::println).count();
D.
This code attempts to use two terminal operations, forEach()
and count()
.
Only one terminal operation is allowed, so the code does not compile, and Option D is correct.
The author of this code probably intended to use peek()
instead of forEach()
.
With this change, the answer would be Option A.