Java中的IntStream forEach()方法
该forEach()方法在Java中用于对该流的每个元素执行操作。使用forEach()JavaIntStream中的方法显示流
语法如下
void forEach(IntConsumer action)
在这里,动作是对元素执行的无干扰动作。
创建IntStream并添加元素
IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);
现在,显示流
intStream.forEach(System.out::println);
以下是forEach()在Java中实现IntStream方法的示例
示例
import java.util.*;
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);
intStream.forEach(System.out::println);
}
}输出结果
15 30 40 60 75 90
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短