The reduce operation

This Terminal operation is called reduce because it processes all of the stream elements and produces one value. It reduces all of the stream elements to one value. But this is not the only operation that does it. The collect operation reduces all of the values of the stream element into one result, too. And, in a way, all Terminal operations reduce. They produce one value after processing of all the elements.

So, you may look at reduce and collect as synonyms that help to add structure and classification to many operations available in the Stream interface. Also, the operations in the reduce group can be viewed as specialized versions of the collect operation, because collect() can be tailored to provide the same functionality, ...

Get Introduction to Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.