Skip to main content


Understanding the definition of a comparator in Java is an important step when trying to choose the right solution for your project. A comparator is a way to compare two objects and determine which one is "greater" or "lesser" based on a certain defined criterion. This comparison can be performed using the Comparable interface which provides a single method compare To() that takes two objects as arguments and returns an integer.