Java Comparator Interface

tutorial and example
tutorial and example

JAVA COMPARATOR INTERFACE

Java comparator is used in a situations when we have to sort an object which does not implement Comparable, or do sorting in a different way than the Comparable.

Comparator is a functional interface since it has only one abstract method compare(). It takes two augments and resides in java.util package.

Example comparator:

Output: