add()
Java中DoubleStream.Builder类的方法将元素添加到正在构建的流中。该方法返回此构建器。
语法如下
default DoubleStream.Builder add(double ele)
此处,ele是要添加到此流中的元素。
要在Java中使用DoubleStream.Builder类,请导入以下包
import java.util.stream.DoubleStream; Create DoubleStream.Builder: DoubleStream.Builder builder = DoubleStream.builder(); Now add some elements: builder.add(23.5); builder.add(33.1); builder.add(35.6); builder.add(53.1);
以下是add()
在Java中实现DoubleStream.Builder方法的示例
import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream.Builder builder = DoubleStream.builder(); builder.add(23.5); builder.add(33.1); builder.add(35.6); builder.add(53.1); builder.add(36.8); builder.add(77.4); builder.add(88.2); builder.add(68.9); builder.build().forEach(System.out::println); } }
输出结果
23.5 33.1 35.6 53.1 36.8 77.4 88.2 68.9