IntStream range(int startInclusive,int endExclusive)以1为增量步长从startInclusive(包括)到endExclusive(不包括)返回顺序的有序IntStream。
用法:
static IntStream range(int startInclusive, int endExclusive)
参数:
IntStream :原始整数值元素的序列。
startInclusive :包含的初始值。
endExclusive :专属上限。
返回值:一个int元素范围的顺序IntStream。
例:
// Implementation of IntStream range
// (int startInclusive, int endExclusive)
import java.util.*;
import java.util.stream.IntStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream
IntStream stream = IntStream.range(6, 10);
// Displaying the elements in range
// including the lower bound but
// excluding the upper bound
stream.forEach(System.out::println);
}
}
输出:
6
7
8
9
注意:IntStream范围(int startInclusive,int endExclusive)本质上像for循环一样工作。可以依次产生一个等效的递增值序列,如下所示:
for (int i = startInclusive; i < endExclusive ; i++)
{
...
...
...
}