gpt4 book ai didi

java - Collection.sort in 是如何实现的?

转载 作者:行者123 更新时间:2023-11-29 06:42:35 25 4
gpt4 key购买 nike

我正在使用 Collection.sort(Array<objectX>, Comperator<objectX>)在 java/Android 中。

在我的比较器中,我使用两个对象的 ID 来比较它们。

我怎么知道这种方法是用什么方法制作的? (快速排序、合并排序...)?

最佳答案

从技术上讲,未指定使用哪种算法(换句话说,它是特定于运行时库的)。

来自 the documentation :

For example, the algorithm used by sort does not have to be a mergesort, but it does have to be stable.

在实践中,它通常根据列表的长度等选择一种或多种排序技术。在 Sun/Oracle 的标准实现中,它在插入排序(如果长度小于 7)和合并排序之间进行选择,否则.

关于java - Collection.sort in 是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9802311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com