Collections vs Arrays regarding sort()

前端 未结 8 2005
北荒
北荒 2021-01-31 03:20

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

8条回答
  •  野的像风
    2021-01-31 04:08

    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.

提交回复
热议问题