DoubleStream reduce(double identity, DoubleBinaryOperator op) example
Description
DoubleStream reduce(double identity, DoubleBinaryOperator op)
performs a reduction on the elements of this stream,
using the provided identity value and an associative accumulation function,
and returns the reduced value.
Syntax
reduce
has the following syntax.
double reduce(double identity, DoubleBinaryOperator op)
Example
The following example shows how to use reduce
.
import java.util.stream.DoubleStream;
//from w w w . ja va 2 s.com
public class Main {
public static void main(String[] args) {
DoubleStream b = DoubleStream.of(1.1, 2.2, 3.3, 4.4, 5.5);
double d = b.reduce(0,(n1,n2)->n1+n2);
System.out.println(d);
}
}
The code above generates the following result.