- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
IntStream forEach() method in Java
The forEach() method is used in Java to perform an action for each element of this stream. Display the stream using the forEach() method in Java IntStream
The syntax is as follows
void forEach(IntConsumer action)
Here, action is a non-interfering action to perform on the elements.
Create IntStream and add elements
IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);
Now, display the stream
intStream.forEach(System.out::println);
The following is an example to implement IntStream forEach() method in Java
Example
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); } }
Output
15 30 40 60 75 90
- Related Articles
- IntStream asLongStream() method in Java
- IntStream peek() method in Java
- IntStream forEachOrdered() method in Java
- IntStream asDoubleStream() method in Java
- IntStream rangeClosed() method in Java
- IntStream sorted() method in Java
- IntStream findFirst() method in Java
- IntStream map() method in Java
- IntStream flatMap() method in Java
- IntStream of() method in Java
- IntStream noneMatch() method in Java
- IntStream anyMatch() method in Java
- IntStream allMatch() method in Java
- IntStream generate() method in Java
- IntStream skip() method in Java

Advertisements