
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Block Lambda Expressions in Java
A lambda block states that lambda expression with multiple statements. It expands the type of operations to perform with a lambda expression. The multiple statements containing bodies are called expression bodies. A lambda expression with expression bodies is called expression lambdas. Whenever we are using expression lambdas, explicitly use a return statement to return a value.
Example
interface NumberFinder { int finder(int number1, int number2); } public class LambdaNumberFinder { public static void main(String args[]) { NumberFinder numberFinder = (number1, number2) -> { int temp = 0; if(number1 > number2) { temp = number1; } else { temp = number2; } return temp; // explicitly return a value }; System.out.println("The valus is : " + numberFinder.finder(10, 5)); } }
Output
The valus is: 10
Advertisements