Let's say I want to sort a list twice, using different comparators each, with the first comparator taking precedence over the second. Is it OK to simply call the SortedList constructor twice, with one call for each comparator?
To clarify why I want to do this, let's say I have an unordered list of
Student objects, which have the fields
Name. Now, the end result that I want to achieve is a list of
Student, where the younger students will appear earlier in the list. However, in the case where there is a group of students with the same age, I want them to appear in sorted-name order. The catch is that I'm restricted to using the comparators which are given to me - which in this case compares the students by either age or name depending on which comparator is specified.
Sorting the list twice, first by name and then by age a la Radix Sort, solves the problem but only if the sorting algorithm involved is stable. I know
Collections.sort is stable, but I'm not sure if
SortedList exerts the same behaviour.
I like J Atkin's
thenComparing answer, and I think this is what I will do, but now I'm just curious whether
SortedList is stable.