Is there a way to create an IntStream
for a range of ints?
Like if I wanted to stream values 1 to 1000, I could invoke some IntStream
static factory to stream that range?
IntStream.forRange(1, 1000).forEach(//do something...
Never mind, I don't know why I missed it in the API documentation after reading it several times...
IntStream.range(1,1000)
rangeClosed
if you want upper bounds to be inclusive.
Feb 29, 2016 at 16:08
.boxed()
if you want to map them to non-integers: IntStream.rangeClosed(1, 10).boxed().map(i -> new User("username " + i)).collect(toImmutableList())
.mapToObj()
: IntStream.rangeClosed(1,10).mapToObj(i -> new User("username " + i)).toList();
Jun 17 at 14:56