Lambda
Lambda
Java
Lambda
expressions
@techwithvishalraj
Lambda expressions
() -> {
//Body of no parameter lambda
}
(p1) -> {
//Body of single parameter lambda
}
(p1,p2) -> {
//Body of multiple parameter lambda
}
@techwithvishalraj
interface Welcome{
public void hello();
}
@FunctionalInterface // it is optional
interface Welcome{
public void hello();
}
welcome.hello();
}
}
output: Hey, Hii :)
Lambda Expression with @techwithvishalraj
single parameter
@FunctionalInterface
interface Welcome{
public void hello(String name);
}
output: 9
@techwithvishalraj
@FunctionalInterface
interface Addition{
public int add(int a, int b);
}
//if there is only one statement, you may or may not use return keyword.
Addition addition = (x, y)-> x+y;
System.out.println(addition.add(4, 5));
output: 9
@FunctionalInterface
interface CheckGrade{
public String check(int a);
}
System.out.println(checkGrade.check(96));
System.out.println(checkGrade.check(38));
}
}
output: A
C
@techwithvishalraj
import java.util.*;
list.forEach(a-> System.out.println(a));
}
}
output: 6
2
4
@techwithvishalraj
Thank
you!
vishal-bramhankar
techwithvishalraj
Vishall0317