~/ learn/ java-from-zero/ cards/ Sorting, choosing the right structure, and fail-fast iterators
1 of 4

Type a Comparator chain that sorts by name then by GPA reversed

Type a Comparator chain that sorts by name then by GPA reversed

Answer

Comparator<Student> cmp = Comparator.comparing(Student::getName) .thenComparingInt(Student::getGpa).reversed();

Comparator.comparing builds a comparator from a key extractor. thenComparing chains a tiebreaker. reversed() flips the whole chain.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/bf4a596f-f0da-4a21-bcba-f2e1f61f1721/flashcard utf-8 LF