Demonstrate Java 8 Streams

master
Hammy 4 years ago
parent ec9fc74ce2
commit 742ad78a60

@ -25,6 +25,12 @@ public class StreamProducts {
.map(StreamProduct::getName) .map(StreamProduct::getName)
.forEach(System.out::println); .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( private static void namesOfLightProductsWeightSortedLoop(

Loading…
Cancel
Save