From d0bc7165e5cfcbc5a6ca070e3586a04a944c2242 Mon Sep 17 00:00:00 2001 From: ibrahimatay Date: Sat, 23 Dec 2023 15:31:50 +0300 Subject: [PATCH] Class SummaryStatistics --- README.md | 4 +++ java-8/pom.xml | 12 +++++++ .../main/java/NewSummaryStatisticClasses.java | 31 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 java-8/src/main/java/NewSummaryStatisticClasses.java diff --git a/README.md b/README.md index 3c4b39b..ae189d2 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,10 @@ This repository contains Java examples that are designed to track and document t * Functional Interfaces * Optional * Method References + * API Improvements + * `java.lang.Object.java.util.IntSummaryStatistics` + * `java.lang.Object.java.util.LongSummaryStatistics` + * `java.lang.Object.java.util.DoubleSummaryStatistics` * [Java 7](java-7/) (September, 2011) diff --git a/java-8/pom.xml b/java-8/pom.xml index 9d206dc..bec2993 100644 --- a/java-8/pom.xml +++ b/java-8/pom.xml @@ -7,6 +7,18 @@ com.ibrahimatay 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + + + 4.0.0 java-8 diff --git a/java-8/src/main/java/NewSummaryStatisticClasses.java b/java-8/src/main/java/NewSummaryStatisticClasses.java new file mode 100644 index 0000000..aef3043 --- /dev/null +++ b/java-8/src/main/java/NewSummaryStatisticClasses.java @@ -0,0 +1,31 @@ +import java.util.IntSummaryStatistics; +import java.util.List; + +public class NewSummaryStatisticClasses { + public static void main(String[] args) { + // Class IntSummaryStatistics + // https://docs.oracle.com/javase%2F8%2Fdocs%2Fapi%2F%2F/java/util/IntSummaryStatistics.html + + // LongSummaryStatistics + // https://docs.oracle.com/javase/8/docs/api/java/util/LongSummaryStatistics.html + + // DoubleSummaryStatistics + // https://docs.oracle.com/javase/8/docs/api/java/util/DoubleSummaryStatistics.html + + List integers = List.of(154, 65, 456, 765,23456,34565432); + + IntSummaryStatistics intSummaryStatistics = new IntSummaryStatistics(); + integers.stream().forEach(intSummaryStatistics::accept); + + System.out.println(intSummaryStatistics); + // IntSummaryStatistics{count=6, sum=34590328, min=65, average=5765054.666667, max=34565432} + + System.out.printf("Max: %d, Min: %d, Ave: %f, Sum: %d", + intSummaryStatistics.getMax(), + intSummaryStatistics.getMin(), + intSummaryStatistics.getAverage(), + intSummaryStatistics.getSum()); + + // Max: 34565432, Min: 65, Ave: 5765054.666667, Sum: 34590328 + } +}