Java规范,哪里说数组的排序应该是稳定的?

标签 java arrays sorting jls

基本上,我刚刚阅读了数组的 javadoc:https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html

它说:

The documentation for the methods contained in this class includes briefs description of the implementations. Such descriptions should be regarded as implementation notes, rather than parts of the specification. Implementors should feel free to substitute other algorithms, so long as the specification itself is adhered to. (For example, the algorithm used by sort(Object[]) does not have to be a MergeSort, but it does have to be stable.)

基本上它说这个文档只是实现说明。但它提到无论如何实现都应该遵守规范。特别是,数组的排序应该是稳定的。所以我很好奇,他们正在谈论什么规范(是 JLS?)以及其中哪里说数组排序应该是稳定的或与之相关的任何内容?

最佳答案

指的是this document ,特别是这句话:

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

关于Java规范,哪里说数组的排序应该是稳定的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34478960/

相关文章:

java - 如何在 http 删除方法中发送 FQDN 作为资源 ID

java - 将类中的所有静态变量放入数组/列表

arrays - Rails - grouped_options_for_select

python - 如何在 pandas DataFrame 中展平 JSON 数组元素

javascript - 如何在js中进行排序?

javascript - 迭代 javascript 数组并求和属性

java - 反转 ArrayList 中每个条目中的字符顺序

java - ANDROID:将 PreviewCallback 图像保存为字节数组中的 .jpg 会导致文件损坏

php - 如何对使用ajax添加的表进行排序

java - rootElement.appendChild(childElement) 在 xml 注释之后