Comparator / Custom Sorting
Learn Comparator / Custom Sorting (Sorting, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Sorting with a Custom Comparator Java's built-in sorts accept a Comparator to define custom ordering instead of natural (ascending) order. A Comparator<T> returns negative/zero/positive to mean "a before b" / "equal" / "a after b".