The Stream.reduce Method

//The following pipeline uses the Stream.reduce operation to calculate the sum 
//of the male members' ages in the collection roster:

	
Integer totalAgeReduce = roster
   .stream()
   .map(Person::getAge)
   .reduce(
       0,
       (a, b) -> a + b);
  • The Stream.reduce method is a general-purpose reduction operation.
  • The reduce operation may take two arguments: identity and accumulator.
  • The reduce operation always returns a new value.

Related concepts

The Stream.reduce Method

The Stream.reduce Method — Structure map

Clickable & Draggable!

The Stream.reduce Method — Related pages: