IntSummaryStatistics getSum() method in Java with Examples

The Java IntSummaryStatistics class's getSum() function is used to retrieve the total number of records in this IntSummaryStatistics.

Syntax:

Parameter: There are no values that can be passed as parameters to this method.

Return Value: The total of the records in this IntSummaryStatistics is returned by this method.

Example 1:

To find the sum of all the elements in an integer stream, utilize the IntSummaryStatistics class as demonstrated by the following Java program.

Implementation:

FileName: IntSummaryExample1.java

Output:

The Sum of the values of the intstream is given by : 595

Example 2:

Using the IntSummaryStatistics class, the Java program given determines the sum of the elements in a list of integers.

Implementation:

FileName: IntSummaryExample2.java

Output:

The sum of the values of the array is 595