自然排序和总排序差异 [英] difference between natural ordering and total ordering

查看:150
本文介绍了自然排序和总排序差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰巧遇到很多类似的语句是不相上下的时候,而分拣整体排序数组或集合和比较是必需的自然顺序使用。

I happened to come across many statements like comparable is used when natural ordering is required while sorting an array or collection and comparator for total ordering.

的什么ü听到的版本可以是相同或不同的具有相同的含义,但最终其两个(比较和可比的接口)之间的显着的因素之一。

The version of what u heard may be same or different with the same meaning but ultimately its one of the distinguishing factors between the two(comparator and comparable interfaces).

不过,无处我能找到的两种排序之间的差异。
如果有人可以用一​​个很好的例子解释这将是更AP preciated:)

But, nowhere I could find a difference between the two types of ordering. If someone can explain it with a good example it will be much appreciated :)

推荐答案

总订货意味着所有的值可以比所有其他值。例如,如果你有一个集合整数字符串自然就没有订单总额(但你可以创造一种)

Total ordering means all values can be compared to all other values. For example, if you have a collection of Integer and String there is no natural total order (but you could invent one)

在Java中,自然顺序被定义为由JVM提供的顺序。这可能不符合什么人可能会认为这是自然秩序。例如字符串进行排序ASCIIbetically。这意味着以Z 到来之前 A 10 为前 2

In Java, the Natural order is defined as the ordering provided by the JVM. This might not match what a people might believe is the natural order. e.g. Strings are sorted ASCIIbetically. meaning Z comes before a and 10 is before 2

<一个href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html\">http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html

此接口强行对实现它的每个类的对象进行整体排序。这个顺序被称为类的自然顺序,和类的compareTo方法作为它的自然比较方法称为

This interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.

这篇关于自然排序和总排序差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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