LongStream builder()返回LongStream的生成器。
用法:
static LongStream.Builder builder()
參數:
- LongStream.Builder:LongStream的可變構建器。流構建器具有生命周期,生命周期從構建階段開始,在此階段可以添加元素,然後過渡到構建階段,此後可能無法添加元素。
返回值:該函數返回LongStream的生成器。
示例1:
// Java code for LongStream builder()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating a LongStream using
// LongStream builder()
LongStream stream = LongStream.builder().add(0).build();
// Displaying the elements
stream.forEach(System.out::println);
}
}
輸出:
0
示例2:
// Java code for LongStream builder()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating a LongStream using
// LongStream builder()
LongStream stream = LongStream.builder().add(1L).add(3L).add(5L).add(7L).add(9L).build();
// Displaying the elements
stream.forEach(System.out::println);
}
}
輸出:
1 3 5 7 9
相關用法
- Java LongStream.Builder accept()用法及代碼示例
- Java LongStream of()用法及代碼示例
- Java LongStream sum()用法及代碼示例
- Java IntStream builder()用法及代碼示例
- Java LongStream iterator()用法及代碼示例
- Java LongStream findFirst()用法及代碼示例
- Java LongStream min()用法及代碼示例
- Java LongStream concat()用法及代碼示例
- Java LongStream max()用法及代碼示例
- Java LongStream toArray()用法及代碼示例
- Java LongStream mapToObj()用法及代碼示例
- Java LongStream mapToDouble()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 LongStream builder() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。