Java Comparator Interface

Java comparator interface is used in a situation 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 of comparator:


Leave a Comment