Java Comparator for Custom Sorting

Comparator is an interface in Java used to define a custom way to compare and sort objects.Use it when: You want to sort objects in a custom way. The class does NOT implement Comparable. You want multiple sorting strategies for the same class. int compare(T o1, T o2) Returns: Negative → o1 comes before o2 Positive → o2 comes before o1 0 → equal order

To view or add a comment, sign in

Explore content categories