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()
以下示例在 Java 中实现 IntStream.Builder build() 方法
示例
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
广告