Skip to content

Commit c1fce0b

Browse files
committed
Implemented Stream if-else logic class
1 parent 27b53f0 commit c1fce0b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.stream.conditional;
2+
3+
import java.util.stream.Stream;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
public class StreamForEachIfElseLogic {
9+
10+
private static final Logger LOG = LoggerFactory.getLogger(StreamForEachIfElseLogic.class);
11+
12+
public static void main(String[] args) {
13+
14+
ifElseLogic();
15+
16+
}
17+
18+
private static void ifElseLogic() {
19+
20+
Stream<Integer> integers = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
21+
22+
integers.forEach(i -> {
23+
if (i.intValue() % 2 == 0) {
24+
LOG.info("{} is even", i);
25+
} else {
26+
LOG.info("{} is odd", i);
27+
}
28+
});
29+
}
30+
}

0 commit comments

Comments
 (0)