Java 中 IntSummaryStatistics getSum() 方法及示例

2025 年 1 月 6 日 | 阅读 2 分钟

Java IntSummaryStatistics 类的 getSum() 函数用于检索此 IntSummaryStatistics 中的记录总数。

语法

参数:此方法不接受任何参数。

返回值:此方法返回此 IntSummaryStatistics 中记录的总和。

示例 1

以下 Java 程序演示了如何使用 IntSummaryStatistics 类来查找整数流中所有元素的总和。

实施

文件名:IntSummaryExample1.java

输出

The Sum of the values of the intstream is given by : 595

示例 2

给出的 Java 程序使用 IntSummaryStatistics 类来确定整数列表中元素的总和。

实施

文件名:IntSummaryExample2.java

输出

The sum of the values of the array is 595