I have array of ints
int array[] = ...
and I can sort it using
Arrays.sort(array);
but Arrays.sort uses quicksort, which sometimes result in O(n^2) complexity. I had an idea to convert it to List and then sort it (mergesort is used, so upper bound is O(n log n)), but the drawback is that it creates a lot of objects due to boxing from int to Integer.
My third approach is this :
array = Arrays.stream(array).sorted().toArray();
I operate only on IntStream, but unfortunately the complexity isn't mentioned in the documentation.
I was looking for similar questions and I have found only this Big-O complexity of java.util.stream.Stream<T>.sorted() which isn't helpful at all, because there are two different answers (first is of course partially wrong, because Arrays.sort isn't always O(n log n)). What about the second one ? I haven't found the proof.