From ca98fbb7062c13129ee3193b679a64ad9da63f84 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Thu, 31 Jan 2019 16:18:59 +0400 Subject: [PATCH] Added Stream Api --- .../list/primitive/PrimitiveCollections.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java b/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java index 50f372e9c9..01372763e9 100644 --- a/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java +++ b/core-java-collections-list/src/main/java/com/baeldung/list/primitive/PrimitiveCollections.java @@ -7,15 +7,20 @@ import it.unimi.dsi.fastutil.ints.IntArrayList; import java.util.Arrays; import java.util.List; +import java.util.OptionalDouble; +import java.util.function.IntPredicate; +import java.util.stream.IntStream; public class PrimitiveCollections { public static void main(String[] args) { - int[] primitives = new int[] {5, 10, 0, 2}; + int[] primitives = new int[] {5, 10, 0, 2, -8}; guavaPrimitives(primitives); + intStream(primitives); + TIntArrayList tList = new TIntArrayList(primitives); cern.colt.list.IntArrayList coltList = new cern.colt.list.IntArrayList(primitives); @@ -29,6 +34,15 @@ public class PrimitiveCollections { System.out.println(fastUtilList); } + private static void intStream(int[] primitives) { + + IntStream stream = IntStream.of(5, 10, 0, 2, -8); + + IntStream newStream = IntStream.of(primitives); + + OptionalDouble average = stream.filter(i -> i > 0).average(); + } + private static void guavaPrimitives(int[] primitives) {