Which is the algorithm implemented in Array.sort?

I’m trying to figure out which algorithm kaolin uses for sorting, but I can’t find any clear answer for that.

And I wanted to know if any other sort of algorithms function exists or if we should implement others alogthrims.

I guess that depends on the target and even runtime. Kotlin probably doesn’t implement sorting by itself, but uses underlying stdlib. And even if asking specifically about JVM or JS, I think this is still not that trivial, because different JVM implementations / JS engines could use different algorithms for sorting. I believe JVM generally uses some variations of either quicksort or mergesort.

The documentation says that it is a stable sort, so it is not quicksort.

Depending on what do you sort. Primitives don’t have identity, so there is no concept of stable/unstable sorting. Documentation for sorting of arrays here: Arrays (Java SE 17 & JDK 17) says it is “Dual-Pivot Quicksort” for primitives and “stable, adaptive, iterative mergesort” or “TimSort” for objects.


Why does it matter to you?

It’s rather unlikely but it all depends on what is that you’re doing