I am working on a small Java utils library called Jools and contains a Range class that provides the functions you need (there is a loadable JAR).
The constructors are either Range(int stop) , Range(int start, int stop) , or Range(int start, int stop, int step) (similar to a for loop), and you can either iterate over it using a lazy evaluation, or use the method toList() to explicitly get a list of ranges.
for (int i : new Range(10)) {...} // i = 0,1,2,3,4,5,6,7,8,9 for (int i : new Range(4,10)) {...} // i = 4,5,6,7,8,9 for (int i : new Range(0,10,2)) {...} // i = 0,2,4,6,8 Range range = new Range(0,10,2); range.toList(); // [0,2,4,6,8]
Amir Rachum Sep 29 '11 at 19:01 2011-09-29 19:01
source share