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...
IntStream range() method in Java The range() method in the IntStream class in Java is used to return a sequential ordered IntStream from startInclusive to endExclusive by an incremental step of 1. This includes the startInclusive as well.
IntStream. range(x,y) would return a stream from x(inclusive) and y(exclusive). IntStream. rangeClosed(x,y) would return a stream from x(inclusive) and y(inclusive).
range() method generates a stream of numbers starting from start value but stops before reaching the end value, i.e start value is inclusive and end value is exclusive. Example: IntStream. range(1,5) generates a stream of ' 1,2,3,4 ' of type int .
Interface IntStream. A sequence of primitive int-valued elements supporting sequential and parallel aggregate operations. This is the int primitive specialization of Stream .
Never mind, I don't know why I missed it in the API documentation after reading it several times...
IntStream.range(1,1000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With