Skip to main content

Lambda Expression in java

 Java Lambda Expression

           Lambda expression provided implementation logic for functional interfaces (interfaces with only one abstract method ) which we will discuss soon.
lambda expression add the essence of functional programming in java . They are functional constructs without classes, which can be passed like objects and executed as required. They also make the modifires, return type and parameter types completely optional.

Syntax of Lambda Expression


(arguments) -> (body)


the syntax of lambda expressions is comprised of three parts:
  1. An argument list  The parameter list should be the same (in terms of number, type, and order of arguments) as that of the abstract method of the interface. For example:
    Syntax:
    () -> { System.out.println("No argument"); }
    OR
    (int argument1, String argument2) -> { System.out.println("Multiple arguments"); }


        Argument types can be eliminated, making them inferred types. i.e. (int argument) and (argument) are same.
    Also, parenthesis () can be eliminated if there is only one argument.
  2. The arrow(->) token
  3. The body:
    The presence of curly braces is not mandatory when the body contains not more than one statement. In addition, the return type of any lambda expression/anonymous function will be the type of the expression that the body evaluates to.


(e1, e2) -> e1.getCountry().compareTo(e2.getCountry())


If the body contains a block of statements, curly braces should enclose them, and a return statement becomes mandatory when the block returns something.


(e1, e2) -> {
    int value = e1.getCountry().compareTo(e2.getCountry());
    return value;
}



Note:    Inferred and declared types cannot be used together, i.e. (int x, y) -> x+y; is invalid.

Comments

Popular posts from this blog

Introduction of php and it's features

 what is php ? what is features of php language? Introduction of PHP  PHP is a server site scripting language. which we use to create a dynamic  content, website  and web application.  PHP language is develop by Rasmus Lerdorf in 1994. In this time, PHP is a most popular scripting language. Most popular website as facebook and yahoo developed by php language. Features of PHP Php is a most popular and secondary used for world wide scripting language. there are many features of php language:- simple and easy to learn open source error reporting faster case sensitive loosely type language independent plateform Simple And easy to learn PHP is a very simple to use read and write.PHP language understandable and user-friendly. user and developer easily identify PHP code. Interpreted language PHP is an interpreted language, which means there is no need for compilation. Interpreters run through a program line by line and execute the code. PHP language no need of compiler...

How to create a table in html

  Hello dosto 🙏🙏 Aaj ham dekhenge ki kaise html Me table create karte hai . Create A Table In Html: Html me table create karne ke liye  for example ham student name ki table banayenge:- <!DOCTYPE html> <html> <head> <Title>Creating a table</title> </head> <body> <table border="1" cellspacing="0"> <tr> <tr>student table</tr> <th>name</th> <th>class</th> <th>address</th> </tr> <tr> <td>ram</td> <td>bca</td> <td>rampur</td> </tr> </tr> </table> </body> </Html> Coding karne ke baad apka Student name ki table ban Jati hai If this information is helpful, To aisi hi coding sekhna chahte to neeche comments kare Thanks 

Introduction of Android and it's features

 What is Android? Describe Android os. Write introduction of Android? Introduction of Android  Android is a mobile operating system developed by Google. It is based on a modified version of the Linux kernel and other open source software, and is designed primarily for touchscreen mobile devices such as smartphones and tablets. Android's user interface is based on direct manipulation, using touch gestures that loosely correspond to real-world actions, such as swiping, tapping and pinching, to manipulate on-screen objects, along with a virtual keyboard for text input. In addition to touchscreen devices, Google has further developed Android TV for televisions, Android Auto for cars, and Wear OS for wrist watches, each with a specialized user interface. Features of Android  Android is a mobile operating system developed by Google. It is used on a wide range of devices, including smartphones, tablets, and wearable devices. Some of the features of Android include:- Customizable...