The following notes are from Udacity-Intro to Java Programming
Thus, numbers (1 < 11 < 12 < ... < 2 < 21 ...) < Uppercase letters < Lowercase letters
Ex:
123 < John < john
lesson1 < lesson10 < lesson2
The term lexicographic order is not defined in the videos. It means the order the computer sorts the strings in. In the computer world, numbers are considered to be smaller than letters of any kind. So they come first. Uppercase letters are smaller than lowercase numbers letters. so "X" comes before "x"
This is another interesting thing about alphabetizing Strings containing numbers in computers. Here is how numbers would be ordered. 1, 11, 12, 13, 14 ... 2, 21, 22, 23 ... Anything that starts with 1 comes before anything that starts with 2. so even 1000 would come before 2.
Thus, numbers (1 < 11 < 12 < ... < 2 < 21 ...) < Uppercase letters < Lowercase letters
Ex:
123 < John < john
lesson1 < lesson10 < lesson2
We can use "compareTo" function to compare the lexicographic order between two strings.
ex: String1.compareTo(string2)
the return value:
0 : if two strings are identical
< 0 : if String1 is lexicographically less than String2
> 0 : if String1 is lexicographically greater than String2
See more detail on
No comments:
Post a Comment