Lambda expression.in Java 8
In below example we use the usual way of creating lambda
expression using arrow syntax and also we used a brand new double colon (::)
operator that Java 8 has to convert a normal method into lambda expression.
//Old way: List<Integer>
list = Arrays.asList(1, 2, 3, 4, 5, 6, 7); for(Integer n:
list) { System.out.println(n); } //New way: List<Integer>
list = Arrays.asList(1, 2, 3, 4, 5, 6, 7); list.forEach(n
-> System.out.println(n)); //or we can use
:: double colon operator in Java 8 list.forEach(System.out::println); |
by: Suvojeet Pal
No comments:
Post a Comment