2 ms·
Collections.sort() just copies the list into an array, sorts the array, and copies the sorted elements back into the list. So it also just sorts an array under
by layer8 4y ago
Collections.sort() just copies the list into an array, sorts the array, and copies the sorted elements back into the list. So it also just sorts an array under the hood. To eliminate the temporary array (at least for ArrayList), the List#sort() method was added in Java 8.
Arrays are usually still preferred over collections in the case of primitive types (int[] etc.).