Language Implementations

What Sorting Algorithm Does Java Use?

Updated June 8, 2026 5 min read

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? +
Java uses Tim Sort for object arrays and collections (stable) and Dual-Pivot Quick Sort for primitive arrays (faster, unstable). The choice depends on whether stability is needed.
What is Dual-Pivot Quick Sort? +
A Quick Sort variant that partitions around two pivots into three regions instead of one, improving performance on many inputs. Java uses it for primitive arrays.

See it in motion

Watch this algorithm and 9 others run step by step in our free interactive visualizer.

▶ Launch Visualiser

Related articles

← Back to all articles