From 742ad78a601e69582d2d5a8534e22659cbcb0a68 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 8 Nov 2020 07:32:04 +0000 Subject: [PATCH] Demonstrate Java 8 Streams --- Java Streams/src/StreamProducts.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Java Streams/src/StreamProducts.java b/Java Streams/src/StreamProducts.java index 038719a..666813a 100644 --- a/Java Streams/src/StreamProducts.java +++ b/Java Streams/src/StreamProducts.java @@ -25,6 +25,12 @@ public class StreamProducts { .map(StreamProduct::getName) .forEach(System.out::println); + // Printing out names without using .map() + streamProducts.stream() + .filter(streamProduct -> streamProduct.getWeight() < 30) + .sorted(comparingInt(StreamProduct::getWeight)) + .forEach(streamProduct -> System.out.println(streamProduct.getName())); + } private static void namesOfLightProductsWeightSortedLoop(