Comparator

Comparator<T> defines a sort order separate from the class. You build it with Comparator.comparing(...), chain it with thenComparing, and reverse it with reversed(). It is used with list.sort and sorted.

Example

personnes.sort(Comparator.comparing(Personne::nom).thenComparing(Personne::age));

Related concepts

The whole glossary