我碰巧遇到很多类似的语句是不相上下的时候,而分拣整体排序数组或集合和比较是必需的自然顺序使用。
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
docs.oracle/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.
更多推荐
自然排序和总排序差异
发布评论