- 热门类别
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 精选阅读
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java 中的 IntStream forEach() 方法
forEach() 方法用于 Java 来对这个流的每个元素执行操作。使用 forEach() 方法在 Java IntStream 中显示流
语法如下
void forEach(IntConsumer action)
这里,action 是在元素上执行的非干扰操作。
创建 IntStream 并添加元素
IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);
现在,显示流
intStream.forEach(System.out::println);
以下是实现 Java 中 IntStream forEach() 方法的示例
示例
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
广告