![]() |
VOOZH | about |
The Stream.forEach(Consumer action) method performs a given action on each element of the stream. It is a terminal operation, which may traverse the stream to produce a result or a side effect.
Example:
12345
Explanation:
void forEach(Consumer<? super T> action)
Example 1: Print Each Element of a Reversely Sorted Integer Stream
10 8 6 4 2
Explanation:
Example 2: Print Each Element of a String Stream
GFG Geeks for GeeksforGeeks
Explanation: forEach(System.out::println) applies the print operation to each element.
Example 3: Print Character at Index 1 from Reversely Sorted String Stream
o e e F
Explanation: