Stuart A. Burkett wrote:A class is said to have a natural ordering if it implements the Comparable interface, in which case it's ordering is decided by the implementation of the compareTo method. If you look at the javadoc for the String.compareTo method it explains how the order is decided.
gurpeet singh wrote:
Stuart A. Burkett wrote:A class is said to have a natural ordering if it implements the Comparable interface, in which case it's ordering is decided by the implementation of the compareTo method. If you look at the javadoc for the String.compareTo method it explains how the order is decided.
not just Comparable interface, but if a class implements Comparator interface then also it is said to have natural ordering. basically natural ordering means that you can COMPARE objects of the class using some property of the objects.
gurpeet singh wrote:not just Comparable interface, but if a class implements Comparator interface then also it is said to have natural ordering. basically natural ordering means that you can COMPARE objects of the class using some property of the objects.
Joey Sanchez wrote:Natural ordering is
1. symbols (#,@,(,&..)
2. numbers
3. space, ?, ¿
4. upercase
5. lowercase
symbols and space, ? are a mess :s
Henry Wong wrote:but unicode is based on ASCII for the range you are referring to
By "natural" sort order, I mean it compares strings the way a human would compare them, as opposed to "ascii-betical" sort ordering that only makes sense to programmers. In other words, "image9.jpg" is less than "image10.jpg", and "album1set2page9photo1.jpg" is less than "album1set2page10photo5.jpg", and "1.2.9.1" is less than "1.2.10.5"
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Henry Wong wrote:
gurpeet singh wrote:
Stuart A. Burkett wrote:A class is said to have a natural ordering if it implements the Comparable interface, in which case it's ordering is decided by the implementation of the compareTo method. If you look at the javadoc for the String.compareTo method it explains how the order is decided.
not just Comparable interface, but if a class implements Comparator interface then also it is said to have natural ordering. basically natural ordering means that you can COMPARE objects of the class using some property of the objects.
Actually Stuart is correct -- when the documentation talks about "natural ordering", it is referring to Comparable objects. You can achieve different sort orders with Comparators, but that is not considered in the documenation as "natural ordering".
Henry
Dan Drillich wrote:
Absolutely and Natural sort order string comparison in Java - is one built in? says -
By "natural" sort order, I mean it compares strings the way a human would compare them, as opposed to "ascii-betical" sort ordering that only makes sense to programmers. In other words, "image9.jpg" is less than "image10.jpg", and "album1set2page9photo1.jpg" is less than "album1set2page10photo5.jpg", and "1.2.9.1" is less than "1.2.10.5"
Crusading Chameleon likes the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|