什么是Java中的排序算法 [英] What is the sorting algorithm for Java

查看:103
本文介绍了什么是Java中的排序算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何的Java内部的数据类型进行排序,为什么?这将是巨大的,如果在特定的算法可以提到

How does java internally sort the datatypes and why ? It would be great if the specific algorithms can be mentioned

推荐答案

7版开始,Oracle的Java实现使用 Timsort 的对象数组大于10的元素,插入排序数组少于这个数字的元素。同样的考虑同时申请<一个href="http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#sort%28java.lang.Object%5b%5d%29"><$c$c>Arrays.sort()和<一href="http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#sort%28java.util.List%29"><$c$c>Collections.sort().在老版本的Java,合并排序代替Timsort。

Beginning with version 7, Oracle's Java implementation is using Timsort for object arrays bigger than 10 elements, and Insertion sort for arrays with less than that number of elements. The same considerations apply for both Arrays.sort() and Collections.sort(). In older versions of Java, Merge sort was used instead of Timsort.

语言(比Oracle的其他)的其他实现可以使用不同的排序算法,因为这不是由规范所规定的。报价集合文档< /一>:

Other implementations of the language (other than Oracle's) might use a different sorting algorithm, as this is not mandated by the specification. Quoting Collections' documentation:

该文档包含在这个类中的多态算法一般包括执行情况的简要说明。这种描述应被视为实现说明,而不是本说明书的部分。实现者应该可以随意替代其他算法,只要本身是坚持规范。 (例如,用于由排序算法不必是一个合并,但它必须是稳定的。)

The documentation for the polymorphic algorithms contained in this class generally includes a brief description of the implementation. 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 does not have to be a mergesort, but it does have to be stable.)

这篇关于什么是Java中的排序算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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