Summary Statistics

In general, statistics are a processed result of the data. The result could be a number, it may be a count, sum, average, min, max etc. In this blog, I give you the sample program for getting the min, max and average using java 8 Summary Statistics.

Summary Statistics Classes

Java 8 provide various class based on data types for get the statistics those are below

  • IntSummaryStatistics
  • LongSummaryStatistics
  • DoubleSummaryStatistics
package com.samplecoder.streams;

import java.util.Arrays;
import java.util.DoubleSummaryStatistics;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.LongSummaryStatistics;

public class SummaryStatistics {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		List<Integer> intNumbers = Arrays.asList(100,3,200,2,1,23,43,545,232);
		IntSummaryStatistics intStatistics = -> item));
		System.out.println("Int Summary \n"+intStatistics);
		LongSummaryStatistics longStatistics = -> item));
		System.out.println("Long Summary \n"+longStatistics);
		List<Number> doubleNumbers = Arrays.asList(100.10,3.2,200.11,2.2,1,2.3,43,545,232);
		DoubleSummaryStatistics doubleStatistics = -> item.doubleValue()));
		System.out.println("Double Summary \n"+doubleStatistics);



Int Summary 
IntSummaryStatistics{count=9, sum=1149, min=1, average=127.666667, max=545}
Long Summary 
LongSummaryStatistics{count=9, sum=1149, min=1, average=127.666667, max=545}
Double Summary 
DoubleSummaryStatistics{count=9, sum=1128.910000, min=1.000000, average=125.434444, max=545.000000}


Now you should know what is a statistic, and what are all the summary statistics classes are available in java 8. And how can we using it. And by that, what are all the possible values you can get.