Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 IntStream for an int range?

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... 
like image 304
tmn Avatar asked Feb 04 '15 04:02

tmn


People also ask

What is IntStream range in Java?

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.

Is IntStream range inclusive?

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).

How does IntStream range () work?

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 .

What is IntStream in java8?

Interface IntStream. A sequence of primitive int-valued elements supporting sequential and parallel aggregate operations. This is the int primitive specialization of Stream .


1 Answers

Never mind, I don't know why I missed it in the API documentation after reading it several times...

IntStream.range(1,1000) 
like image 68
tmn Avatar answered Oct 11 '22 20:10

tmn