Collections vs Arrays regarding sort() What is the difference between these two regarding sort() method? I know Arrays\' sort() is using binary search for sort(), what about Co
Arrays.sort() sorts Arrays i.e. Objects that are in continuous memory locations. It works on array input.
Collections.sort() can sort objects on both continuous and discrete memory locations i.e. It can work on both ArrayList and LinkedList. Collections.sort() internally converts List into Array of objects and calls Arrays.sort() to sort them. It always create extra copy of original list objects. For ArrayList as input, it creates extra copy to maintain mutability of original array. For LinkedList as input, a new array is created for better performance purpose.
Collection.sort is used when you dealing with lists and arrays.sort is sued when dealing with arrays. But internally Collection.sort uses Arrays.sort method only. Now internally sorting is done based in Timosrt technique instead of merge sort , because stable, adaptive arrays takes O(nlogn) comparisons in Merge sort but in Timsort worst case it will take O(nlogn) and in worst case storage requies n/2 in Timsort but it is not in the case of Merge sort technique.