Skip to content

Commit

Permalink
Class SummaryStatistics
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimatay committed Dec 23, 2023
1 parent 3f8e311 commit d0bc716
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions java-8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>com.ibrahimatay</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
<modelVersion>4.0.0</modelVersion>

<artifactId>java-8</artifactId>
Expand Down
31 changes: 31 additions & 0 deletions java-8/src/main/java/NewSummaryStatisticClasses.java
Original file line number Diff line number Diff line change
@@ -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<Integer> 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
}
}

0 comments on commit d0bc716

Please sign in to comment.