IntSummaryStatistics getCount() method in Java with Examples

The Java IntSummaryStatistics class's getCount() function is used to determine the number of records in this IntSummaryStatistics.

Syntax:

public long getCount()

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

Return Value: The function gives back the total number of records in this IntSummaryStatistics.

Example 1:

The number of elements in a list of integers is counted and printed by the SummaryCount class.

Implementation:

FileName: SummaryCountExample1.java

Output:

The total count of the given values is 11

Example 2:

The summaryStatistics() function is used by the CountSummaryExample2 class to generate an IntStream of integers and gather statistics into an IntSummaryStatistics object. The total number of values in the stream is then printed after obtaining the count of elements in the stream using the getCount() method.

Implementation:

FileName: CountSummaryExample2.java

Output:

The total number of values present in the stream is: 11