How to use Collectors.summarizingInt() in Java 8

330 total views, 4 views today

Welcome to Java 8 series. In this tutorial, you will learn about how to use Collectors.summarizingInt() in Java 8

If you would like to learn about Java 8 Stream operations.Please check out this link.


Collectors.summarizingInt() in Java 8 is a useful and wonderful operation of Stream collect().It provides us the statistics of the stream of elements. It returns a class that gives us all necessary statistical information such as average, sum, count, min and max.

Collectors.summarizingInt() returns a class called IntSummaryStatistics.

Collectors.summarizingInt() syntax

public static <T> Collector<T,?,IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper)

As per documentation, returns a Collector which applies an int-producing a mapping function to each input element, and returns summary statistics for the resulting values.


Collectors.summarizingInt() example

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;

public class StaticReference
    public static void main(String[] args)

        List<Integer> list = Arrays.asList(1, 2, 3, 15, 6, 17, 8);

        IntSummaryStatistics stats = -> i));
        System.out.println("Average : " + stats.getAverage());
        System.out.println("Count : " + stats.getCount());
        System.out.println("Min : " + stats.getMin());
        System.out.println("Max : " + stats.getMax());
        System.out.println("Sum : " + stats.getSum());


Average : 7.428571428571429
Count : 7
Min : 1
Max : 17
Sum : 52


References : summarizingInt()

I hope you like this tutorial. Thanks for reading and Please leave us a comment below!

Tags :

About the Author


Hey There, My name is Rajasekar and I am the author of this site. I hope you are liking my tutorials and references. Programming and learning new technologies are my passion. The ultimate idea of this site is to share my knowledge(I am still a learner :)) and help you out!. Please spread your words about us ( and give a thumbs up :) Feel free to contact me for any queries!.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.