In Java 8 we can also use double colon(::) as the method reference. By using double colon(::) operator we can easily convert normal method into lambda expression.
The below example will show you how you will convert normal method into lambda expressions and use as a method reference inside lambda expression.
import java.util.*;
public class demo1
{
public void show(String name)
{
System.out.println("My Name is :"+name);
}
public static void main(String ss[])
{
List<String> names=new ArrayList<String>();
names.add("manish");
names.add("sandeep");
names.add("ravinder");
names.add("akki");
names.forEach(System.out::println);
demo1 d=new demo1();
names.forEach(d::show);
}
}
0 Comment(s)