Collection.sort(list)和list.sort()之间的区别 [英] Difference between Collection.sort(list) and list.sort()

查看:287
本文介绍了Collection.sort(list)和list.sort()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么理由我更喜欢 Collection.sort(list)方法而不是简单地调用 list.sort()?内部 Collection.sort 仅调用 List sort 方法>无论如何。>

Is there any reason why I should prefer Collection.sort(list) method over simply calling the list.sort()? Internally Collection.sort merely calls the sort method of the List class anyway.

几乎每个人都告诉我使用 Collection.sort ,这简直令人惊讶。为什么?

It's just surprising that almost everyone is telling me to use Collection.sort. Why?

推荐答案

方法 List.sort(比较器) 引用是在Java 8中引入的,而实用方法 Collections.sort 自Java 1.2以来一直存在。

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.

因此,你会在互联网上找到很多提及该实用方法的参考资料,但这只是因为它已经在JDK中使用了很长时间。

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.

注意 Collections.sort的实施变更 是在8u20进行的

这篇关于Collection.sort(list)和list.sort()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆