What Sorting Algorithm Does Java Use?
Java is one of the few languages that deliberately uses two different sorting algorithms depending on the data type. Knowing which is used — and why — explains a lot about how the JDK balances speed and correctness.
Objects: Tim Sort
Arrays.sort(Object[]) and Collections.sort() use Tim Sort because it is stable — equal elements keep their order, which is required for correct multi-key sorting of objects.
Primitives: Dual-Pivot Quick Sort
Arrays.sort(int[]) and the other primitive overloads use Dual-Pivot Quick Sort by Vladimir Yaroslavskiy. It partitions around two pivots into three regions, improving cache behavior. Stability is meaningless for primitives, so the faster unstable sort is used.
Frequently asked questions
What sorting algorithm does Java use? +
What is Dual-Pivot Quick Sort? +
See it in motion
Watch this algorithm and 9 others run step by step in our free interactive visualizer.
▶ Launch Visualiser