Java 中的 LongStream rangeClosed()
原文:https://www.geeksforgeeks.org/longstream-rangeclosed-java/
LongStream range closed(long start inclusive,long endInclusive) 返回一个从 startInclusive(包含)到 endInclusive(包含)的 LongStream,增量步长为 1。
语法:
static LongStream rangeClosed(long startInclusive, long endInclusive)
参数:
- longstream: The sequence of original long-value elements.
- 开始包含:包含初始值。
- 结束时间:包含上限。
返回值:长元素范围的连续长流。
例:
// Implementation of LongStream rangeClosed
// (long startInclusive, long endInclusive)
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream
LongStream stream = LongStream.rangeClosed(-4L, 3L);
// Displaying the elements in range
// including the lower and upper bound
stream.forEach(System.out::println);
}
}
输出:
-4
-3
-2
-1
0
1
2
3
注意:LongStream range closed(long start inclusive,long endInclusive)基本上像 for 循环一样工作。递增值的等价序列可以按如下顺序产生:
for (int i = startInclusive; i <= endInclusive ; i++)
{
...
...
...
}
版权属于:月萌API www.moonapi.com,转载请注明出处