Java 8 – Iterate through List
In this example, We will show you simple example about, How to Iterate through list example in Java 8. The example has been tested and output shared in the same post.
Example Program
package com.dineshkrish; import java.util.ArrayList; import java.util.List; /** * * @author Dinesh Krishnan * */ public class ListForEach { public static void main(String[] args) { // defining the array list List<String> numbers = new ArrayList<String>(); // adding the elements to list numbers.add("One"); numbers.add("Two"); numbers.add("Three"); numbers.add("Four"); numbers.add("Five"); numbers.add("Six"); numbers.add("Seven"); numbers.add("Eight"); numbers.add("Nine"); numbers.add("Ten"); // iterating the elements over the list numbers.forEach(number -> System.out.println(number)); } }
Output
One Two Three Four Five Six Seven Eight Nine Ten
References
1. JavaDoc – List Interface
2. JavaDoc – ArrayList Class
3. Java 8 – Iterable forEach() method
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet