Maybe Array.sort() isn’t that frequently used, as data sorting is often done by the database?
Maybe Array.sort() isn’t that frequently used, as data sorting is often done by the database?
Most Java application code doesn't, but it typically uses libraries that do. A sorted array is a priority queue, a binary search tree, etc.
If you have an application that is truly bottlenecked the performance of number-sorting in any measurable way, then you most probably didn't write it in Java. It's not really a number crunching language for a variety of reasons.
You end up using libraries like fastutil, which is "generic code" templated by C preprocessor macros,
This is planned as phase two of Project Valhalla [0]:
The second phase will focus on generics, extending the generic type system
to support instantiation with inline classes (which will include primitives),
and extending the JVM to support specialized layouts.
[0] https://cr.openjdk.org/~briangoetz/valhalla/sov/01-backgroun...(Scala has specialization and value classes and opaque types so that covers a fairly big range but they make interop with Java tricky.)
This includes JEP 401 "Flattened Heap Layouts for Value Objects" [1, JEP 402 "Enhanced Primitive Boxing" [2], and I think also "Value Objects" [3] and "Universal Generics" [4].
It is a huge task with many dependencies and requires careful design. It feels like it might finally make it in the next long term release.
[0] https://openjdk.org/jeps/12
[1] https://openjdk.org/jeps/401
[2] https://openjdk.org/jeps/402