LongStream rangeClosed(long startInclusive,long endInclusive)以增量为1返回从startInclusive(包括)到endInclusive(包括)的LongStream。
用法:
static LongStream rangeClosed(long startInclusive, long endInclusive)
参数:
- LongStream : 一系列原始long值元素。
- startInclusive : 包含的初始值。
- endInclusive : 包含上限。
返回值:用于long元素范围的顺序LongStream。
例:
// 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 rangeClosed(long startInclusive,long endInclusive)基本类似于for循环。可以依次产生一个等效的递增值序列,如下所示:
for (int i = startInclusive; i <= endInclusive ; i++) { ... ... ... }
相关用法
- Java IntStream rangeClosed()用法及代码示例
- Java LongStream of()用法及代码示例
- Java LongStream sum()用法及代码示例
- Java LongStream findFirst()用法及代码示例
- Java LongStream iterator()用法及代码示例
- Java LongStream sorted()用法及代码示例
- Java LongStream max()用法及代码示例
- Java LongStream min()用法及代码示例
- Java LongStream parallel()用法及代码示例
- Java LongStream skip()用法及代码示例
- Java LongStream sequential()用法及代码示例
- Java LongStream range()用法及代码示例
- Java LongStream summaryStatistics()用法及代码示例
- Java LongStream concat()用法及代码示例
- Java LongStream toArray()用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 LongStream rangeClosed() in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。