~/ 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/e2581eb0-6bac-4452-bc1c-018638c166da/flashcard utf-8 LF