
Similar to other classes in Java, this class also needs a package that has to be imported first. How does Range Function work in Java?įirst, let us see how the IntStream range works in Java. This method returns a sequential LongStream of long elements mentioned in the range as parameters.

Syntax of LongStream range static LongStream range(int startInclusive, int endExclusive)

This method returns a sequential IntStream of int elements mentioned in the range as parameters. endExclusive: The last value or upper bound which is excluded in the range.startInclusive: The initial value which is included in the range.IntStream: This is a sequence of int-valued elements which are of primitive type.Syntax of IntStream range static IntStream range(int startInclusive, int endExclusive)

Let us see the syntax of the range method in Java. In the case of LongStream, the only difference is that LongStream values are getting added. In this method, startInclusive (inclusive) and endExclusive (exclusive) are the two parameters that are used with an incremental step as, it is mentioned, the starting value will be included and the ending value will be excluded. In IntStream class, it helps in returning sequentially ordered values of IntStream in the range mentioned as parameters of the function. In Java, the Range method is available in IntStream as well as LongStream class.
