DEV Community

Discussion on: For Loop in different programming languages

Collapse
 
thomas_graf profile image
Thomas Graf • Edited

Java 9 IntStream has a new static method:

iterate​(int seed, IntPredicate hasNext, IntUnaryOperator next)

IntStream.iterate(0, i -> i < 10, i -> i + 1)
            .forEach(System.out::println)

is equivalent to the following for-i loop, but more in a functional style

for(int i = 0; i < 10; i++) {
    System.out.println(i);
}