Java.util.IntSummaryStatistics class with Examples
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.lang.Object ↳ java.util.IntSummaryStatistics
Constructors

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.
Syntax:
public IntSummaryStatistics()

IntSummaryStatistics(count, min, max, sum): Initializes the various data members with the parameters passed during invocation.
Syntax:
public IntSummaryStatistics(long count, int min, int max, long sum) throws IllegalArgumentException
Methods:

accept() – This function adds the passed integer into the statistical data.
Syntax:
public void accept(int value)

combine(): This function combines the statistical data of the passed IntSummaryStatistics object with the current statistical data.
Syntax:
public void combine(IntSummaryStatistics other)

getCount(): This method returns the count of the number of integers processed.
Syntax:
public final long getCount()

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

getAverage(): This method returns the average of all the integers processed.
Syntax:
public final double getAverage()

getMin(): This method returns the minimum integer of all the integers processed.
Syntax:
public final int getMin()

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

toString(): This method returns the string representation of all the statistical data contained in the object.
Syntax:
public String toString()
 URL class in Java with Examples
 JavaFX  Cursor class with examples
 AbstractSet Class in Java with Examples
 Calendar Class in Java with examples
 Date class in Java (With Examples)
 StringBuilder Class in Java with Examples
 Java AWT  Cursor class with examples
 Java.lang.InheritableThreadLocal Class with Examples
 Math class methods in Java with Examples  Set 2
 BitSet class methods in Java with Examples  Set 3
 ResourceBundle and ListResourceBundle class in Java with Examples
 Java.util.LongSummaryStatistics class with Examples
 Java.util.DoubleSummaryStatistics class with Examples
 Java.util.concurrent.Exchanger class with Examples
 Java Guava  binomial(int n, int k) of LongMath Class with Examples
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 intSummaryStatistics.accept(iterator.next()); } // 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" ); System.out.println(intSummaryStatistics.toString()); } } 
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}
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/IntSummaryStatistics.html
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.