Java 8 Streams: How to call once the Collection.stream() method and retrieve an array of several aggregate values [duplicate]

北城余情 提交于 2019-12-06 01:58:55

Here's how to solve this with standard JDK 8 API:

IntSummaryStatistics summary = personsList.stream().collect(
    Collectors.summarizingInt(Person::getAge));
System.out.println("Count: " + summary.getCount());
System.out.println("Max  : " + summary.getMax());
System.out.println("Min  : " + summary.getMin());

Result:

Count: 3
Max  : 35
Min  : 25
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!