From c1fce0bcd25144a1fb7e429aa7c6127cea49daa8 Mon Sep 17 00:00:00 2001 From: RoscoeLotriet Date: Mon, 24 Sep 2018 10:26:15 +0200 Subject: [PATCH] Implemented Stream if-else logic class --- .../conditional/StreamForEachIfElseLogic.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core-java-8/src/main/java/com/baeldung/stream/conditional/StreamForEachIfElseLogic.java diff --git a/core-java-8/src/main/java/com/baeldung/stream/conditional/StreamForEachIfElseLogic.java b/core-java-8/src/main/java/com/baeldung/stream/conditional/StreamForEachIfElseLogic.java new file mode 100644 index 0000000000..e8800415dc --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/stream/conditional/StreamForEachIfElseLogic.java @@ -0,0 +1,30 @@ +package com.baeldung.stream.conditional; + +import java.util.stream.Stream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StreamForEachIfElseLogic { + + private static final Logger LOG = LoggerFactory.getLogger(StreamForEachIfElseLogic.class); + + public static void main(String[] args) { + + ifElseLogic(); + + } + + private static void ifElseLogic() { + + Stream integers = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + + integers.forEach(i -> { + if (i.intValue() % 2 == 0) { + LOG.info("{} is even", i); + } else { + LOG.info("{} is odd", i); + } + }); + } +}