Java 8 introduces a parallel algorithm for multi-threaded sorting of arrays, in the form of the overloaded Arrays.sort()
methods.
Why does it not also provide a Collections.parallelSort()
, for multi-threaded sorting of a List
?
Java 8 introduces a parallel algorithm for multi-threaded sorting of arrays, in the form of the overloaded Arrays.sort()
methods.
Why does it not also provide a Collections.parallelSort()
, for multi-threaded sorting of a List
?
A List
does not necessarily allow efficient implementation of the same parallel sorting algorithms that an array does. You may be able to directly apply it to an ArrayList
, but most likely not to a LinkedList
, due to its lack of efficient random access. There are efficient multi-threaded sorting algorithms for that kind of list, but they are different from a random-access list.
And, in fact, the thread-safe implementation of the List
interface may not support efficient external multi-threaded sorting at all, due to synchronization. Providing a generic sorting algorithm for those would be impossible, and in fact a parallel algorithm might be slower on them than a sequential algorithm.