LongStream range(long startInclusive,long endExclusive)以增量步長1從startInclusive(包括)到endExclusive(不包括)返回順序的有序LongStream。
用法:
static LongStream range(long startInclusive, long endExclusive)
參數:
- LongStream : 一係列原始long值元素。
- startInclusive : 包含的初始值。
- endExclusive : 專屬上限。
返回值:用於long元素範圍的順序LongStream。
例:
// Implementation of LongStream range
// (long startInclusive, long endExclusive)
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream
LongStream stream = LongStream.range(6L, 10L);
// Displaying the elements in range
// including the lower bound but
// excluding the upper bound
stream.forEach(System.out::println);
}
}
輸出:
6 7 8 9
注意:LongStream range(long startInclusive,long endExclusive)本質上像for循環。可以依次產生一個等效的遞增值序列,如下所示:
for (int i = startInclusive; i < endExclusive ; i++) { ... ... ... }
相關用法
- Java LongStream sum()用法及代碼示例
- Java LongStream of()用法及代碼示例
- Java LongStream toArray()用法及代碼示例
- Java LongStream parallel()用法及代碼示例
- Java LongStream mapToObj()用法及代碼示例
- Java LongStream sorted()用法及代碼示例
- Java LongStream summaryStatistics()用法及代碼示例
- Java LongStream concat()用法及代碼示例
- Java LongStream mapToDouble()用法及代碼示例
- Java LongStream rangeClosed()用法及代碼示例
- Java LongStream builder()用法及代碼示例
- Java LongStream boxed()用法及代碼示例
- Java LongStream asDoubleStream()用法及代碼示例
- Java LongStream skip()用法及代碼示例
- Java LongStream min()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 LongStream range() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。