In JDK 1.8, the first instruction of the java.util.List#sort(Comparator) method is as follows:
Object[] a = this.toArray();
It is worth copying the list into an array, sorting it and reset each node of the list into a sorted value from the array.
It seems that when sorting an ArrayList it is not possible to copy the values into a temporary array. I'm right? If not, what were the creators of the method guided by?
java sorting arrays list java-8
the_kaba
source share