Java中的IntStream.Builder build()方法
该build()
方法生成流。它将构建器转换为构建状态。它返回构建的流。首先,将元素添加到流中
IntStream.Builder builder = IntStream.builder(); builder.add(10); builder.add(25); builder.add(33);
现在流处于构建阶段
builder.build().forEach(System.out::println);
语法如下
IntStream build()
以下是build()
在Java中实现IntStream.Builder方法的示例
例
import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream.Builder builder = IntStream.builder(); System.out.println("Elements in the stream..."); builder.add(10); builder.add(25); builder.add(33); builder.add(42); builder.add(55); builder.add(68); builder.add(75); builder.build().forEach(System.out::println); } }
输出结果
Elements in the stream... 10 25 33 42 55 68 75