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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。