Java SE 8 Programmer II — Question 196
Which two methods from the java.util.stream.Stream interface perform a reduction operation? (Choose two.)
Answer options
- A. count ()
- B. collect ()
- C. distinct ()
- D. peek ()
- E. filter ()
Correct answer: A, B
Explanation
The correct answers are A and B because both count() and collect() perform reduction operations; count() aggregates elements into a single count, while collect() gathers elements into a collection. The other options, distinct(), peek(), and filter(), do not perform reductions but instead transform or filter the stream without aggregating results.