VOOZH about

URL: https://www.geeksforgeeks.org/java/intstream-foreachordered-method-java/

⇱ IntStream forEachOrdered() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

IntStream forEachOrdered() method in Java

Last Updated : 6 Dec, 2018
IntStream forEachOrdered(IntConsumer action) performs an action for each element of this stream in encounter order. IntStream forEachOrdered(IntConsumer action) is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. Syntax :
void forEachOrdered(IntConsumer action)
Parameter : IntConsumer represents an operation that accepts a single int-valued argument and returns no result. This is the primitive type specialization of Consumer for int. Note : forEachOrdered(IntConsumer action) performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order. Example 1 :
Output:
2
3
4
5
Example 2 :
Output:
5
6
7
8
9
10
Example 3 :
Output :
5
6
7
8
9
10
Comment