Comparator vs Comparable in Java: Key Differences Explained
The short answer Comparable lets a class define its own single natural order. You implement compareTo() inside the class, and Collections.sort(list) uses it. Comparator defines an order outside the class. You implement compare() in a separate class or lambda. So…