DoubleStream sum() example

Description

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;
//from   ww w .ja  v  a  2 s . c o  m
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.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder