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 min,max和零均值
Long.MIN_VALUE。
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(int value)
记录一个新的
int值为汇总信息。
|
void |
accept(long value)
记录一个新的
long值为汇总信息。
|
void |
combine(LongSummaryStatistics other)
结合另一个
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 min,max和零均值
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
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.