This method takes a single parameter which is a functional interface. So, you can pass lambda expression as an argument.
default void forEach(Consumer<super T>action)
Exmaple of foreach() Method:
import java.util.*; public class Example{ public static void main(String[] args) { List<String> list=new ArrayList<String>(); list.add("a"); list.add("b"); list.add("b"); list.add("c"); list.add("d"); list.forEach( // lambda expression (names)->System.out.println(names) ); } }
No comments:
Post a Comment