Lambda Expressions
Lambda Expressions
1)Java Lambda expressions are a new and important feature included in jdk8
2) A lambda expression provides a way to represent one method interface using an expression
3) A lambda expression is like a method, it provides a list of formal parameters and a body
() ->expression
or
(parameters) ->expression
or
public interface I {
void m1();
}
public class Test {
I i=()->System.out.println("Lambda--");
i.m1();
}
}
CJC by Kunal sir [LAMBDA EXPRESSIONS]
public interface I1 {
I1 i1=(x,y)->System.out.println(x+" "+y);
I1 i11=(int x, String y)->{
System.out.println(x);
System.out.println(y);
};
i1.m2(2, "CJC");
i11.m2(3,"abc");
}
}
public interface I2 {
int m1();
I2 i3=()->10;
I2 i2=()->{
System.out.println("m1----I2");
return 5;
};
int x=i2.m1();
int y= i3.m1();
System.out.println(x);
System.out.println(y);
list.add("ccc");
list.add("bbb");
list.add("aaa");
/*Consumer<String>
c=(Stringnm)>System.out.println(nm);;
list.forEach(c);*/
/*list.forEach((String nm)-
>System.out.println(nm));*/
list.forEach(System.out::println);
/* for(String s:list)
{
System.out.println(s);
}*/
m.put("aaa", "Java");
m.put("bbb", "Python");
m.put("ccc", "Spring");
System.out.println(val);
});
/*Set<String> keys=m.keySet();
for(String key:keys)
{
System.out.println(key);
System.out.println(m.get(key));
}*/