java - IntSummaryStatistics的summaryStatistics方法
问题描述
为什么空 IntStream 上的 summaryStatistics() 方法返回整数的最大值和最小值作为流中存在的最大和最小 int 值?
IntStream intStream = IntStream.of();
IntSummaryStatistics stat = intStream.summaryStatistics();
System.out.println(stat);
输出:
IntSummaryStatistics{count=0, sum=0, min=2147483647, average=0.000000, max=-2147483648}
- 返回这些值有什么意义?
- 它不应该考虑错误的结果吗?
解决方案
请参阅IntSummaryStatistics.getMax()和IntSummaryStatistics.getMin()文档,当没有记录值时,此处描述了这种确切的行为。
在这些极端情况下返回这些是明智的。我将在这里解释这种行为IntSummaryStatistics.getMin()
。
示例:假设列表至少包含一个条目。无论该条目的整数值是什么,它都不会大于Integer.MAX_VALUE
。因此,当没有条目时返回此值是有意义的,以便为用户提供洞察力。
同样适用IntSummaryStatistics.getMax()
推荐阅读
- r - 如何提取 R 中 GJRM 包中 post.check 函数的 QQPLOT?
- python - LSTM 分类器的准确率低
- firebase - Firebase 分析每小时粒度报告
- sharepoint - 使用 CSOM 将 AD 组添加到 Sharepoint Online 组
- javascript - 为什么传递道具无限循环会使我的应用程序崩溃并且甚至不更新道具?
- elasticsearch - 快速引导大量分层数据的策略以及在任何记录发生更改时更新 Elasticsearch 中单个分层 json 文档的方法
- realm - Realm Cocoa:潜在的线程/通知问题(或者我从文档中遗漏了一些东西)
- c# - 尝试从 android 设备 C# Xamarin 建立蓝牙连接时出错
- python - 代码中断迭代 - 仅打印第一项
- redirect - 仅重定向到裸域