Java 8 – Lambda Expression example

Lambda Expression

  • Lambda expression is a new feature in Java 8 .
  • Alternative to anonymous class implementation of interfaces ( with single abstract method ).
  • syntax : (parameters) -> { body of statements }

Example – Sorting the list of Employees using comparator

Lets use the following employee class objects for adding to the list.

Old way ( before Java 8 )

Using Lambda expression ( available from Java 8 )

Output

Sorted by Name :
Name : Hari , Salary : 2000
Name : Naveen , Salary : 1000
Name : Raju , Salary : 9000

 

References

Java 8 – new features and enhancements with examples

http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html

 

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

www.000webhost.com