 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DoubleStream sum() method in Java
The sum() method of the DoubleStream class in Java returns the sum of elements in this stream.
The syntax is as follows
double sum()
To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
Create DoubleStream and add some elements
DoubleStream doubleStream = DoubleStream.of(23.6, 45.3, 59.6, 60.6, 73.6, 84.7, 94.8);
Now, sum the elements of the stream
double sum = doubleStream.sum();
The following is an example to implement DoubleStream sum() method in Java
Example
import java.util.*;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(23.6, 45.3, 59.6, 60.6, 73.6, 84.7, 94.8);
      double sum = doubleStream.sum();
      System.out.println("The sum of all the elements of the stream = "+sum);
   }
}
Output
The sum of all the elements of the stream = 442.2
Advertisements
                    