Implemented Stream if-else logic class

This commit is contained in:
RoscoeLotriet 2018-09-24 10:26:15 +02:00
parent 27b53f070a
commit c1fce0bcd2
1 changed files with 30 additions and 0 deletions

View File

@ -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<Integer> 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);
}
});
}
}