devxlogo

New Way to Iterate a List in Java 8

New Way to Iterate a List in Java 8

We can see that the method println is referred by System.out using ::

import java.util.*;public class NewForEach {   public static void main(String args[])   {      List empNames = new ArrayList();            empNames.add("Andrew");      empNames.add("Mohin");      empNames.add("Rajan");            empNames.forEach(System.out::println);   }}
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist