Skip to content
Related Articles

Related Articles

Improve Article

Java.util.DoubleSummaryStatistics class with Examples

  • Last Updated : 27 Jun, 2019
Geek Week

The DoubleSummaryStatistics class is present in java.util package. It takes a collection of Double objects and is useful in the circumstances when we are dealing with a stream of large precision real numbers. It maintains a count of the number of values it has processed, their sum and various other statistics. The class can also be used with Streams.

It is useful in the sense that it maintains a running sum, average, etc. of the doubles and hence can be used in the manipulation of statistical data.

Class Hierarchy

↳ java.util.DoubleSummaryStatistics


  1. DoubleSummaryStatistics(): A default constructor which initializes the count and sum to zero, and sets max to Double.NEGATIVE_INFINITY and min to Double.POSITIVE_INFINITY.


    public DoubleSummaryStatistics()


  1. accept(): nThis function adds the passed double into the statistical data.


    public void accept(double value)
  2. combine(): This function combines the statistical data of the passed DoubleSummaryStatistics object with the current statistical data.


    public void combine(DoubleSummaryStatistics other)
  3. getCount(): This method returns the count of the number of doubles processed.


    public final long getCount()
  4. getSum(): This method returns the sum of all the doubles processed.


    public final long getSum()
  5. getAverage(): This method returns the average of all the doubles processed.


    public final double getAverage()
  6. getMin(): This method returns the minimum double of all the doubles processed.


    public final double getMin()
  7. getMax(): This method returns the maximum double of all the doubles processed.


    public final double getMax()
  8. toString(): This method returns the string representation of all the statistical data contained in the object.


    public String toString()

    Example To demonstrate DoubleSummaryStatistics in action.

    // Java program to demonstrate
    // DoubleSummaryStatistics class
    import java.util.*;
    public class DoubleSummaryStatisticsDemo {
        public static void main(String[] args)
            DoubleSummaryStatistics doubleSummaryStatistics
                = new DoubleSummaryStatistics();
            List<Double> list = new LinkedList<>();
            Iterator<Double> iterator = list.listIterator();
            while (iterator.hasNext()) {
                // Add the doubles to the
                // DoubleSummaryStatistics object
            // Use various methods to obtain the data
            System.out.println("The count of values is "
                               + doubleSummaryStatistics
            System.out.println("The average of values is "
                               + doubleSummaryStatistics
            System.out.println("The sum of values is "
                               + doubleSummaryStatistics
            System.out.println("The maximum of values is "
                               + doubleSummaryStatistics
            System.out.println("The minimum of values is "
                               + doubleSummaryStatistics
            System.out.println("The string representation is");
    The count of values is 10
    The average of values is 10468.29537
    The sum of values is 104682.9537
    The maximum of values is 45664.7
    The minimum of values is 0.0
    The string representation is
    DoubleSummaryStatistics{count=10, sum=104682.953700, min=0.000000, average=10468.295370, max=45664.700000}


    Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

    My Personal Notes arrow_drop_up
Recommended Articles
Page :