Java AdvancedLesson 81Free preview
Java Advanced Sorting
This lesson is part of Java · All levels
Summary
The advanced sequence includes sorting complex objects with custom Comparators and incorporating several criteria at once. You can compile criteria using thenComparing(), and the sequencing can run parallel to big data. For the record, Arrays.sort uses dual-pivot quicksort for the primitive type.
Key points
- Comparator.comparing(criteria) and then added thenComparing() to the next criteria
- Reversed() reverses the direction of a Comparator
- List.sort(cmp) running the in-place order on the list
- Arrays.sort() for primitive using dual-pivot quicksort, for object using TimSort
- The TimSort-based object sequence is stable, i.e. the equivalent element maintains its order
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.