Java Learner logo

Module 11: Collections Framework Deep Dive

Lesson focus

Comparable vs Comparator

Implement natural ordering or supply external comparators for flexible sorting.

Comparable defines natural ordering inside the class via compareTo.

Comparator objects allow multiple sorting strategies without modifying the class.

Use Comparator factory methods (comparing, thenComparing) for concise definitions.

Lesson quiz

How do you define multiple sort orders without changing the class?

Next lesson →