summarizing
summarizingDouble()
summarizingDouble(ToDoubleFunction<? super T> mapper)
Example
public void summarizingDouble() {
List<Double> doubleList = Arrays.asList(0.002, 23.43, 23.32, 8.76567);
System.out.println("Contents of the list - " + doubleList);
Stream<Double> doubleStream = doubleList.stream();
DoubleSummaryStatistics doubleSummaryStatistics = doubleStream.collect(Collectors.summarizingDouble(e -> e));
System.out.println("Summary statistics of the stream - " + doubleSummaryStatistics);
}
Output
Contents of the list - [0.002, 23.43, 23.32, 8.76567]
Summary statistics of the stream - DoubleSummaryStatistics{count=4, sum=55.517670, min=0.002000, average=13.879417, max=23.430000}
summarizingInt()
summarizingInt(ToIntFunction<? super T> mapper)
Example
public void summarizingInt() {
List<Integer> integerList = Arrays.asList(23, 23, 8);
System.out.println("Contents of the list - " + integerList);
Stream<Integer> integerStream = integerList.stream();
IntSummaryStatistics intSummaryStatistics = integerStream.collect(Collectors.summarizingInt(e -> e));
System.out.println("Summary statistics of the stream - " + intSummaryStatistics);
}
Output
Contents of the list - [23, 23, 8]
Summary statistics of the stream - IntSummaryStatistics{count=3, sum=54, min=8, average=18.000000, max=23}
summarizingLong()
Example
public void summarizingLong() {
List<Long> longList = Arrays.asList(2343L, 2332L, 876567L);
System.out.println("Contents of the list - " + longList);
Stream<Long> longStream = longList.stream();
LongSummaryStatistics longSummaryStatistics = longStream.collect(Collectors.summarizingLong(e -> e));
System.out.println("Summary statistics of the stream - " + longSummaryStatistics);
}
Output
Contents of the list - [2343, 2332, 876567]
Summary statistics of the stream - LongSummaryStatistics{count=3, sum=881242, min=2332, average=293747.333333, max=876567}