Your questions answered: all about Lambdas and friends
In mathematics and computing generally, a lambda expression is a function: for some or all combinations of input values it specifies an output value. Lambda expressions in Java introduce the idea of functions into the language. In conventional Java terms lambdas can be understood as a kind of anonymous method with a more compact syntax that also allows the omission of modifiers, return type, and in some cases parameter types as well.
The basic syntax of a lambda is either
(parameters) -> expression
or
(parameters) -> { statements; }
1. (int x, int y) -> x + y // takes two integers and returns their sum 2. (x, y) -> x - y // takes two numbers and returns their difference 3. () -> 42 // takes no values and returns 42 4. (String s) -> System.out.println(s) // takes a string, prints its value to the console, and returns nothing 5. x -> 2 * x // takes a number and returns the result of doubling it 6. c -> { int s = c.size(); c.clear(); return s; } //takes a collection, clears it, and returns its previous size
return keyword in a block body are the same as those for an ordinary method body.size and clear, with appropriate parameters and return types.More precisely, it could take a collection; equally, it could
take some other compatible type. See the last syntax note.