What\'s the shortest way to get an Iterator over a range of Integers in Java? In other words, implement the following:
/**
* Returns an Iterator over the in
An example using the guava framework. Note that this will not materialize the set (although you have to read the ContiguousSet implementation to verify that).
import com.google.common.collect.ContiguousSet;
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.DiscreteDomains;
class RangeIterator {
public Iterator range(int start, int length) {
assert length > 0;
Range dim_range = Ranges.closedOpen(start, start + length);
DiscreteDomain ints = DiscreteDomains.integers();
ContiguousSet dim = dim_range.asSet(ints);
return dim.iterator();
}
}