public class LongSummaryStatistics extends Object implements LongConsumer, IntConsumer
This class is designed to work with (though does not require) streams. For example, you can compute summary statistics on a stream of longs with:
LongSummaryStatistics stats = longStream.collect(LongSummaryStatistics::new,
LongSummaryStatistics::accept,
LongSummaryStatistics::combine);
LongSummaryStatistics
can be used as a
Stream.collect(Collector) reduction}
target for a stream. For example:
LongSummaryStatistics stats = people.stream()
.collect(Collectors.summarizingLong(Person::getAge));
This computes, in a single pass, the count of people, as well as the minimum,
maximum, sum, and average of their ages.Collectors.toLongStatistics()
on a parallel stream, because the parallel
implementation of Stream.collect()
provides the necessary partitioning, isolation, and merging of results for
safe and efficient parallel execution.
This implementation does not check for overflow of the sum.
Constructor | Description |
---|---|
LongSummaryStatistics() |
Construct an empty instance with zero count, zero sum,
Long.MAX_VALUE min, Long.MIN_VALUE max and zero
average. |
Modifier and Type | Method | Description |
---|---|---|
void |
|