Java Streams - DoubleStream sum() example








DoubleStream sum() returns the sum of elements in this stream.

Syntax

sum has the following syntax.

double sum()

Example

The following example shows how to use sum.

import java.util.stream.DoubleStream;
// ww w  .j av a 2 s  .c om
public class Main {
  public static void main(String[] args) {
    DoubleStream d = DoubleStream.of(1.2,2.3,4.5);
    
    double v = d.sum();
    
    System.out.println(v);
   
  }
}

The code above generates the following result.