Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Java.util.IntSummaryStatistics class with Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The IntSummaryStatistics class is present in java.util package. It takes a collection of Integer objects and is useful in the circumstances when we are dealing with a stream of integers. It maintains a count of the number of integers 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 integers and hence can be used in the manipulation of statistical data.

Class Hierarchy

↳ java.util.IntSummaryStatistics


  1. IntSummaryStatistics(): A default constructor which initializes the count and sum to zero, and sets max to Integer.MIN_VALUE and min to Integer.MAX_VALUE.


    public IntSummaryStatistics()
  2. IntSummaryStatistics(count, min, max, sum): Initializes the various data members with the parameters passed during invocation.


    public IntSummaryStatistics(long count, int min, int max, long sum)
                         throws IllegalArgumentException


  1. accept() – This function adds the passed integer into the statistical data.


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


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


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


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


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


    public final int getMin()
  7. getMax(): This method returns the maximum integer of all the integers processed.


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


    public String toString()
  9. Example To demonstrate IntSummaryStatistics in action.

    // Java program to demonstrate
    // IntSummaryStatistics class
    import java.util.*;
    public class IntSummaryStatisticsDemo {
        public static void main(String[] args)
            IntSummaryStatistics intSummaryStatistics
                = new IntSummaryStatistics();
            List<Integer> list
                = Arrays.asList(10, 20, 30, 40, 50);
            Iterator<Integer> iterator = list.listIterator();
            while (iterator.hasNext()) {
                // Add the integers to the IntSummaryStatistics object
            // Use various methods to obtain the data
            System.out.println("The count of values is "
                               + intSummaryStatistics.getCount());
            System.out.println("The average of values is "
                               + intSummaryStatistics.getAverage());
            System.out.println("The sum of values is "
                               + intSummaryStatistics.getSum());
            System.out.println("The maximum of values is "
                               + intSummaryStatistics.getMax());
            System.out.println("The minimum of values is "
                               + intSummaryStatistics.getMin());
            System.out.println("The string representation is");


    The count of values is 5
    The average of values is 30.0
    The sum of values is 150
    The maximum of values is 50
    The minimum of values is 10
    The string representation is
    IntSummaryStatistics{count=5, sum=150, min=10, average=30.000000, max=50}


    My Personal Notes arrow_drop_up
Last Updated : 24 Jun, 2019
Like Article
Save Article
Similar Reads
Related Tutorials