Example usage for java.util.stream Collectors summarizingInt

List of usage examples for java.util.stream Collectors summarizingInt

Introduction

In this page you can find the example usage for java.util.stream Collectors summarizingInt.

Prototype

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

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    IntSummaryStatistics incomeStats = Employee.persons().stream()
            .collect(Collectors.summarizingInt(Employee::getIncome));
    System.out.println(incomeStats);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    List<Person> persons = Arrays.asList(new Person("Max", 18), new Person("Peter", 23),
            new Person("Pamela", 23), new Person("David", 12));

    IntSummaryStatistics ageSummary = persons.stream().collect(Collectors.summarizingInt(p -> p.age));

    System.out.println(ageSummary);
}