Difference between Comparable and Comparator
Understanding the definition of a comparator in Java is an important step when trying to choosethe right solution for your project. A comparator is a way to compare two objects and determinewhich one is “greater” or “lesser” based on a certain defined criterion. This comparison can beperformed using the Comparable interface which provides a single method compare To() thattakes two objects as arguments and returns an integer.