These terminal operation performs a reduction on the elements.
int reduce(int identity,
IntBinaryOperator op)
Parameters:
identity - the identity value for the accumulating function
op - a function for combining two values
OptionalInt reduce(IntBinaryOperator op)
Parameters:
op - a function for combining two values
Examples
package com.logicbig.example.intstream;
import java.util.stream.IntStream;
public class ReduceExample {
public static void main(String... args) { IntStream intStream = IntStream.range(1, 5); int i = intStream.reduce(0, (a, b) -> (a + b) * 2); System.out.println(i); } }