Saturday, 23 May 2020

forEach Loop in Single Line of Code using JAVA 8 Feature



import java.util.List;

import java.util.ArrayList;



public class ForeachTest {



   public static void main(String args[]) {

    // create List

List<String> subjects = new ArrayList<String>();

subjects.add("C");

subjects.add("C++");

subjects.add("JAVA");

subjects.add(".NET");



//apply forEach in single line of code

subjects.forEach(System.out::println);

 

   }

}


















No comments:

Post a Comment

JTable Hide and Show in Java Swing