In Java, Arrays.sort () uses a quick sort for a primitive type. Arrays.sort (), on the other hand, uses Merge sorting for objects. And the same goes for Collection.sort () , which also uses Merge sorting. To sort the collection, sort sorting of arrays underneath is used. So, in a simple sense, I can say that primitives are sorted using quick sort, but objects are sorted using Merge sort.
I guess this has something to do with the sorting algorithm. There is so much discussion of SO on Quick sort vs Merge sort, like this and. It seems that there are conflicting statements for which it is better, which is understandable, since it depends on the data sets.
My understanding
- In place: Quick sorting. Merge sorting can be implemented in place for the Linked List
- External storage data: merge sort wins.
- Sort list (supported by any form of linked list): sorting wins by volume. Link
The Android API seems to follow the same pattern as Java. This is what I found in Arrays.java
public static void sort(long[] array) {
DualPivotQuicksort.sort(array);
}
And this,
public static void sort(Object[] array) {
ComparableTimSort.sort(array);
}
, Merge Java Android? ?