ExotickBoyPl ExotickBoyPl - 1 year ago 101
Java Question

For loop - like Python range function

I was wondering if in Java there is a function like the python range function.


and it would return


This was an easy way to make for enhanced loops. It would be great to do this in Java because it would make for loops a lot easier. Is this possible?

Answer Source

Java 8 has added IntStream (similar to apache commons IntRange), so you don't need external lib now.

IntStream.range(0, 3).forEachOrdered(n -> {
    //work on n here

forEach can be used in place of forEachOrdered too if order is not important.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download