Saturday, November 15, 2025
HomeLanguagesJavaDoubleStream summaryStatistics() in Java

DoubleStream summaryStatistics() in Java

DoubleStream summaryStatistics() returns an DoubleSummaryStatistics describing various summary data about the elements of this stream like count of number of elements in the DoubleStream, average of all elements present in DoubleStream, minimum and maximum element in the DoubleStream and so on. This is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect.

Syntax :

DoubleSummaryStatistics summaryStatistics()

Parameters :

  1. DoubleSummaryStatistics : A state object for collecting statistics such as count, min, max, sum, and average.

Return Value : DoubleSummaryStatistics summaryStatistics() returns an DoubleSummaryStatistics describing various summary data about the elements of this stream.

Note : DoubleStream summaryStatistics() is a special case of a reduction. A reduction operation, also known as fold takes a sequence of input elements and combines them into a single summary result by repeated application of a combining operation. The combining operation can be finding the sum or maximum of a set of numbers.

Example : Using DoubleStream summaryStatistics() to get the DoubleSummaryStatistics of elements present in given DoubleStream.




// Java code for DoubleStream summaryStatistics()
// to get various summary data about the
// elements of the stream.
import java.util.stream.DoubleStream;
import java.util.DoubleSummaryStatistics;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an DoubleStream
        DoubleStream stream = 
                  DoubleStream.of(4.2, 5.3, 6.5, 7.1);
  
        // Using DoubleStream summaryStatistics()
        DoubleSummaryStatistics summary_data = 
                         stream.summaryStatistics();
  
        // Displaying the various summary data
        // about the elements of the stream
        System.out.println(summary_data);
    }
}


Output :

DoubleSummaryStatistics{count=4, sum=23.100000, min=4.200000, average=5.775000, max=7.100000}
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6890 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS