Difference between Collection.sort(list) and list.sort()

前端 未结 3 1935
野性不改
野性不改 2020-12-10 00:44

Is there any reason why I should prefer Collection.sort(list) method over simply calling the list.sort()? Internally Collection.sort m

3条回答
  •  再見小時候
    2020-12-10 01:14

    The method List.sort(comparator) that you are refering to was introduced in Java 8, whereas the utility method Collections.sort has been there since Java 1.2.

    As such, you will find a lot of reference on the Internet mentioning that utility method but that's just because it has been in the JDK for a lot longer.

    Note that the change in implementation for Collections.sort was made in 8u20.

提交回复
热议问题