In this recipe, you will learn how to apply an action to all the elements of the stream. We will use three methods: two terminal operations, the forEach() and forEachOrdered(), and an intermediate operation, the peek() method.
Applying an action to every element of a stream
Getting ready
The example of this recipe has been implemented using the Eclipse IDE. If you use Eclipse or other IDE such as NetBeans, open it and create a new Java project.
How to do it...
Follow these steps to implement the example:
- First, we will implement some auxiliary classes we will use in the example. Create a class named Person with the...