How to iterate through Java List? This tutorial demonstrates the use of ArrayList, Iterator and a List.
There are 7 ways you can iterate through List.
- Simple For loop
- Enhanced For loop
- Iterator
- ListIterator
- While loop
- Iterable.forEach[] util
- Stream.forEach[] util
Java Example:
You need JDK 13 to run below program as point-5 above uses stream[] util.
void java.util.stream.Stream.forEach[Consumer