- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 forEachOrdered() method in Java
The forEachOrdered() method in Java assures that each element is processed in order for streams that have a defined encounter order.
The syntax is as follows
void forEachOrdered(IntConsumer action)
Here, the action parameter is a non-interfering action to be performed on the elements.
Create an IntStream and add elements to the stream
IntStream intStream = IntStream.of(50, 70, 80, 100, 130, 150, 200);
Now, use the forEachOrdered() method to display the stream elements in order
intStream.forEachOrdered(System.out::println);
The following is an example to implement IntStream forEachOrdered() 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(50, 70, 80, 100, 130, 150, 200); intStream.forEachOrdered(System.out::println); } }
Output
50 70 80 100 130 150 200
Advertisements