什么是Java中的IntStream.Builder accept()方法
使用IntStream.Builderaccept()方法将元素插入IntStream。它将元素添加到正在构建的流中。
语法如下:
void accept(int t)
在这里,参数t是输入参数。
元素如下所示插入流中:
builder.accept(10); builder.accept(15); builder.accept(25); builder.accept(39); builder.accept(45);
以下是accept()在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 of the stream...");
builder.accept(10);
builder.accept(15);
builder.accept(25);
builder.accept(39);
builder.accept(45);
builder.accept(55);
builder.accept(80);
builder.build().forEach(System.out::println);
}
}输出
Elements of the stream... 10 15 25 39 45 55 80
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短