Renewed Comparator: Everything You Should Know
This lesson teaches you how to use the power of the newly added methods in the Comparator interface to write concise and efficient Comparators.
Introduction to the Comparator
interface
Comparator
is an interface that is used to define how a collection must be sorted. In Java 7, it had just 2 methods – compare()
and equals()
. The enhanced Comparator
in Java 8 now has 19 methods.
However, the Comparator
is still a functional interface as it has only one abstract method, i.e., compare()
.
Comparator
now supports declarations via lambda expressions as it is a Functional Interface. We saw this in our lambda expressions chapter as well. Below is the list of methods in the Comparator
interface.
Get hands-on with 1400+ tech skills courses.