Java中的IntStream summaryStatistics()方法
的summaryStatistics()
在IntStream类方法用于返回关于该流的元素摘要数据。语法如下:
IntSummaryStatistics summaryStatistics()
创建一个IntStream并添加一些元素:
IntStream intStream = IntStream.of(30, 60, 90);
现在,获取有关以上元素的摘要数据:
IntSummaryStatistics details = intStream.summaryStatistics();
以下是summaryStatistics()
在Java中实现IntStream方法的示例:
示例
import java.util.stream.IntStream; import java.util.IntSummaryStatistics; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(30, 60, 90); IntSummaryStatistics details = intStream.summaryStatistics(); System.out.println("Details = "+details); } }
输出结果
Details = IntSummaryStatistics{count=3, sum=180, min=30, average=60.000000, max=90}