Lambda expression was introduced in Java 8.
Java lambda expressions are Java’s first step into functional programming.
A lambda expression is an anonymous function. A function that doesn’t have a name and doesn’t belong to any class.
Syntax of Lambda Expression
(parameters) -> {expression or statements}
Examples:
Zero parameter:
() -> System.out.println(“no parameters”);
One parameter:
(param) -> System.out.println(“Single param: ” + param);
Multiple parameters :
(param1, param2) -> System.out.println(“Multiple params: ” + param1 + “, ” + param2);
Functional interfaces provide target types for lambda expressions and method references. Please visit Functional interfaces for more stuff.
Let’s have a look into the below codes for better understanding of Lambda Expressions.
Output
Using Lambda for looping through list
Output
Using Lambda for Running a Thread
Output