Utilize a lambda expression within the ArrayList’s forEach() method to print each item contained in the list.
import public |
The forEach() method executes an action on every item within a list, typically defined by a lambda expression compatible with Java’s Consumer interface’s accept() method.
For further understanding of lambda expressions, you can refer to our Java Lambda Expression tutorial.
|
Parameter |
Description |
action |
Necessary: Either a Consumer object or a lambda expression that executes an action on each item. |