2

From Arrays.sort source code:

public static void sort(int[] a) {
    sort1(a, 0, a.length);
}

And then :

private static void sort1(int x[], int off, int len) {
    // Insertion sort on smallest arrays
    if (len < 7) {
        [...]
    }

    [...]
    if (len > 7) {
        [...]
    }
    [...]
}

Where this magic number 7 come from and why?

Link to the source code

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
JohnJohnGa
  • 15,446
  • 19
  • 62
  • 87

1 Answers1

-1

I believe the Java sort algorithm switches from mergesort to quicksort when the list gets small enough. The source references a text, you might want to check there if you're curious.

Vyassa Baratham
  • 1,457
  • 12
  • 18