Video in progress

Which algorithm runs inside Arrays.sort, and is there a difference between a primitive array and an object array?

Yes. For primitive arrays (int[], double[]) it uses a dual-pivot quicksort, which is fast but not stable. For object arrays and List.sort it uses TimSort, which is stable and guaranteed O(n log n).

📖 Answer

For primitives, stability doesn't matter: you can't tell two 5s apart. So the fastest option was chosen there: dual-pivot quicksort (which switches to insertion sort on small pieces). In newer JDKs there is also a fallback to heap sort on pathological inputs, so the worst case is O(n log n) as well.

For objects, order matters. Say orders were first sorted by date and now you sort by status: those with the same status must keep their date order. TimSort guarantees that. It finds the already-sorted pieces (runs) in real data and merges them, so on a nearly sorted list it works close to O(n).

int[] nums = {5, 1, 4};
Arrays.sort(nums);                 // dual-pivot quicksort

List<User> users = loadUsers();
users.sort(Comparator.comparing(User::age)); // TimSort, stable

For large arrays there is also Arrays.parallelSort: on a multi-core machine it splits the work and sorts it using the ForkJoin pool.