FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 223   



From Java8 you can use forEach to iterate over a List, you can see it in action in following example.

import java.util.ArrayList;
import java.util.List;

public class IterateListWithForEach {
    public static void main(String[] args) {
        List<String> colors = new ArrayList<>();
        colors.add("red");
        colors.add("green");
        colors.add("blue");

        colors.forEach((value) -> {
            System.out.println(value);
        });

    }
}

###Output:

red
green
blue

You can see all other possible ways of iterating over a List in this example https://fastfoodcoding.com/tutorials/1495534152971/iterating-on-a-list-in-java




On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News