IntStream summaryStatistics() returns an IntSummaryStatistics describing various summary data about the elements of this stream like count of number of elements in the IntStream, average of all elements present in IntStream, minimum and maximum element in the IntStream and so on. This is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect.
Syntax :
IntSummaryStatistics summaryStatistics()
Parameters :
- IntSummaryStatistics : A state object for collecting statistics such as count, min, max, sum, and average.
Return Value : IntSummaryStatistics summaryStatistics() returns an IntSummaryStatistics describing various summary data about the elements of this stream.
Note : IntStream summaryStatistics() is a special case of a reduction. A reduction operation, also known as fold takes a sequence of input elements and combines them into a single summary result by repeated application of a combining operation. The combining operation can be finding the sum or maximum of a set of numbers.
Example 1 : Using IntStream summaryStatistics() to get the IntSummaryStatistics of elements present in given IntStream.
// Java code for IntStream summaryStatistics() // to get various summary data about the // elements of the stream. import java.util.stream.IntStream; import java.util.IntSummaryStatistics; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream IntStream stream = IntStream.of(4, 5, 6, 7); // Using IntStream summaryStatistics() IntSummaryStatistics summary_data = stream.summaryStatistics(); // Displaying the various summary data // about the elements of the stream System.out.println(summary_data); } } |
Output :
IntSummaryStatistics{count=4, sum=22, min=4, average=5.500000, max=7}
Example 2 :Using IntStream summaryStatistics() to get the IntSummaryStatistics of elements present in given range.
// Java code for IntStream summaryStatistics() // to get various summary data about the // elements of the stream. import java.util.stream.IntStream; import java.util.IntSummaryStatistics; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream of elements // in range [5, 9) IntStream stream = IntStream.range(5, 9); // Using IntStream summaryStatistics() IntSummaryStatistics summary_data = stream.summaryStatistics(); // Displaying the various summary data // about the elements of the stream System.out.println(summary_data); } } |
Output :
IntSummaryStatistics{count=4, sum=26, min=5, average=6.500000, max=8}
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- DoubleStream summaryStatistics() in Java
- LongStream summaryStatistics() in Java
- java.util.stream.IntStream/LongStream | Search an element
- IntStream iterator() in Java
- IntStream rangeClosed() in Java
- IntStream map(IntUnaryOperator mapper) in Java
- IntStream findFirst() in Java
- IntStream parallel() in Java
- IntStream empty() in Java with examples
- IntStream distinct() in Java with examples
- IntStream peek() in Java with examples
- IntStream average() in Java with Examples
- IntStream max() in Java with examples
- IntStream min() in Java with Examples
- IntStream count() in Java with examples
- IntStream skip() in Java
- IntStream filter() in Java with examples
- IntStream concat() in Java
- IntStream anyMatch() in Java with examples
- IntStream allMatch() in Java with examples
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.

