Which two methods from the java.util.stream.Stream interface perform a reduction operation? (Choose two.)
Which two methods from the java.util.stream.Stream interface perform a reduction operation? (Choose two.)
In the java.util.stream.Stream interface, the count() and collect() methods both perform reduction operations. The count() method counts the number of elements in the stream and returns it as a long value, effectively reducing the stream to a single count value. The collect() method is a more general form of reduction that allows the results of the stream to be accumulated into a container like a List, Set, or Map by taking a Collector as a parameter. Both are terminal operations that reduce the stream to a single result.
a and b,tested
A, B correct. count(): The count() method returns the count of elements in the stream as a long value. It is a terminal operation that reduces the stream to a single value, which is the count of elements. collect(): The collect() method is a more general reduction operation that allows you to accumulate elements of a stream into a mutable result container, such as a List, Set, or Map. It takes a Collector as a parameter, which specifies the rules for accumulating the elements. It is also a terminal operation that reduces the stream to a single value, which is the result of the accumulation.
A and B are correct since reduction must take each element and combine them into single element/value.