public class LongSummaryStatistics extends Object implements LongConsumer, IntConsumer
此课程旨在与(但不需要)工作( streams) 。 例如,您可以使用以下方式计算长流的汇总统计信息:
LongSummaryStatistics stats = longStream.collect(LongSummaryStatistics::new, LongSummaryStatistics::accept, LongSummaryStatistics::combine);
LongSummaryStatistics可以用作一个Stream.collect(Collector)减少}目标为stream 。 例如:
LongSummaryStatistics stats = people.stream() .collect(Collectors.summarizingLong(Person::getAge));
这个计算单次通过了人数,以及年龄的最小值,最大值,总和和平均值。
Collectors.toLongStatistics()上并行流,因为并行执行Stream.collect()提供了必要的隔离,隔离和结果安全,高效的并行执行的合并。
此实现不检查总和的溢出。
| Constructor and Description |
|---|
LongSummaryStatistics()
用零计数,零和,
Long.MAX_VALUE分钟,
Long.MIN_VALUE最大和零平均值构造一个空实例。
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(int value)
在摘要信息中记录一个新的
int值。
|
void |
accept(long value)
在摘要信息中记录一个新的
long值。
|
void |
combine(LongSummaryStatistics other)
将另一个
LongSummaryStatistics的状态
LongSummaryStatistics到一个。
|
double |
getAverage()
返回记录的值的算术平均值,如果没有记录值,则返回零。
|
long |
getCount()
返回记录的值的计数。
|
long |
getMax()
返回记录的最大值,如果没有记录值,则返回
Long.MIN_VALUE
|
long |
getMin()
返回记录的最小值,如果没有记录值,则返回
Long.MAX_VALUE 。
|
long |
getSum()
返回记录的值的总和,如果没有记录值,则返回零。
|
String |
toString()
返回对象的字符串表示形式。
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitandThenandThenpublic LongSummaryStatistics()
Long.MAX_VALUE分钟,
Long.MIN_VALUE最大和零平均值。
public void accept(int value)
int值。
accept在接口
IntConsumer
value - 输入值
public void accept(long value)
long值。
accept在界面
LongConsumer
value - 输入值
public void combine(LongSummaryStatistics other)
LongSummaryStatistics的状态
LongSummaryStatistics到一个。
other - 另一个
LongSummaryStatistics
NullPointerException - 如果
other为空
public final long getCount()
public final long getSum()
public final long getMin()
Long.MAX_VALUE 。
Long.MAX_VALUE
public final long getMax()
Long.MIN_VALUE
Long.MIN_VALUE如果没有
public final double getAverage()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.