The reason why Arrays tool class sort () in JDK7 uses different sorting algorithms for basic types and objects is What?

  java, question

For example, the sorting method sort () in java.util.Arrays tool class in JDK7 uses different sorting algorithms for basic types and objects.
For basic types, DualPivotQuicksort sorting algorithm is adopted, as follows:

public static void sort(int[] a) {
 DualPivotQuicksort.sort(a);
 bracket

For the Object type, the ComparableTimSort sorting algorithm is adopted, as follows:

public static void sort(Object[] a) {
 if (LegacyMergeSort.userRequested)
 legacyMergeSort(a);
 Else
 ComparableTimSort.sort(a);
 bracket

May I ask the reason for this choice is What?

The reason is as follows. Merge sort sort () application scenario:

  1. Sorts Object types. Fast sorting is unstable and has no effect on basic types, but has effect on Object types. Merge sort is stable.

  2. Sort large arrays. Fast sort () is implemented recursively, and stack overflow will occur when the array size is too large, while Merge sort sort () is implemented non-recursively, so this problem does not exist.