IntSummaryStatistics Class in JavaThe IntSummaryStatistics class is one of the most important classes present in the java.util.package. It provides a set of integer objects which are used at the time of dealing with a stream of integers. It keeps the count of the number of integers processed, their sum and various other statistics. We can also use these classes with Streams. The class is mainly used in the manipulation of statistical data. java.lang.Object → java.util.IntSummaryStatistics ConstructorsThe IntSummaryStatistics class has following two constructors: 1. IntSummaryStatistics()It is a default constructor that will initialize the sum and count to zero and set min to Integer.MIN_VALUE and max to Integer.MAX_VALUE. Syntax 2. IntSummaryStatistics(count, min, max, sum)It is a parameterized constructor that will initialize the sum, count, min and max with the given parameters. Syntax IntSummaryStatistics Class MethodsThe IntSummaryStatistics class has more than one method for performing the manipulation of statistical data. Let's understand each one of them one by one with an example. accept(int value) MethodThe accept() method is an important method provided by the IntSummaryStatistics class that is used for accepting the given value into this summary information. Syntax Parameter It accepts an integer value as a parameter that is to be recorded into this IntSummaryStatistics. Return value NA. Let's take an example to understand the use of the accept() method. IntSummaryStatisticsExample1.java Output: combine(IntSummaryStatistics other) MethodThe combine() method is another important method provided by the IntSummaryStatistics class that is used for combining two IntSummaryStatistics objects. Syntax Parameter It accepts an object of IntSummaryStatistics, which is going to combine with the current statistical data. Return value NA. Let's take an example to understand the use of the combine() method. IntSummaryStatisticsExample2.java Output: getCount() MethodThe getCount() method is another important method provided by the IntSummaryStatistics class that is used to get the count of the number of integers processed. Syntax Parameter NA. Return value It returns the count of the numbers of integers processed. Let's take an example to understand the use of the getCount() method. IntSummaryStatisticsExample3.java Output: getSum() MethodThe getSum() method is another important method provided by the IntSummaryStatistics class that is used to get the sum of all integers processed. Syntax Parameter NA. Return value It returns the sum of all integers processed. Let's take an example to understand the use of the getSum() method. IntSummaryStatisticsExample4.java Output: getAverage() MethodThe getSum() method is another important method provided by the IntSummaryStatistics class that is used to get the average of all integers processed. Syntax Parameter NA. Return value It returns the average of all integers processed. Let's take an example to understand the use of the getAverage() method. IntSummaryStatisticsExample5.java Output: getMin() MethodThe getMin() method is another important method provided by the IntSummaryStatistics class that is used to get the minimum Integer of all integers processed. Syntax Parameter NA. Return value It returns the minimum Integer of all integers processed. Let's take an example to understand the use of the getMin() method. IntSummaryStatisticsExample6.java Output: getMax() MethodThe getMax() method is another important method provided by the IntSummaryStatistics class that is used to get the maximum Integer of all integers processed. Syntax public final int getMax() Parameter NA. Return value It returns the maximum Integer of all integers processed. Let's take an example to understand the use of the getMax() method. IntSummaryStatisticsExample7.java Output: toString() MethodThe toString() method is used to get the string representation of all statistical data contained in the project. Syntax Parameter NA. Return value It returns the string representation of the IntSummaryStatistics object. Let's take an example to understand the use of the toString() method. IntSummaryStatisticsExample8.java Output:
Next TopicJava ProcessBuilder Example
