0% found this document useful (0 votes)
9 views2 pages

Comparator 0 Lambda

JAVA PROGRAMMING NOTES

Uploaded by

sania.patil22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Comparator 0 Lambda

JAVA PROGRAMMING NOTES

Uploaded by

sania.patil22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

A lambda expression is a feature introduced in Java 8 that allows you to write short

and concise code. It's essentially a way to express an instance of a functional


interface (an interface with only one abstract method) in a more compact form.
Lambda expressions are often used for implementing the Comparator interface or
any functional interfaces.

In the example above, (int a, int b) represents the parameters, and a + b is the
expression that is executed when the lambda expression is invoked.
Uses:
 Lambda expressions simplify the syntax for functional programming.
 They're used for writing short blocks of code that can be passed around (like
sorting, filtering, or mapping).
 It allows writing inline implementation of functional interfaces, like Runnable,
ActionListener, or Comparator.
Comparator in Java

The Comparator interface in Java is used to define a custom comparison


logic for objects. It allows sorting objects in an order other than their natural
order (which is defined by the Comparable interface).

You might also like