Introduction to Lambda Expression with Examples
Java 8 comes up with one great features called Lambda Expressions. It's first step to the functional programming. With Lambda expression we can treat functionality as method arguments i.e. you can pass a method as argument to another method. Previously we use to write anonymous class if we wanted to pass some method as argument to another method but with lambda expression, we can pass a plain method as argument. Lambda expressions is a anonymous function i.e. It has arguments, a body and return type. Syntax of Lambda Expression : (Argument(s)) → {Body} Eg : (int x, int y, int z) - > {return x+y+z}; (String msg) - > {System.out.println(msg);} () - > { return 100;} Structure of Lambda Expression : It can have zero, one or more number of parameters. For empty set of parameters, Empty parentheses are used. e.g () -> 100 Type of the passed parameter can be explicitly declared or can be taken from context. e.g. (int x) is same as (x). One...