This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The term lexicographically can be thought of as "alphabetically". That is, "apple" comes before "bug" and so on. Also, shorter words come before longer words. "apple" comes before "apples" This is also dictionary order. The only difference is that on a computer we also deal with special characters like !@#$%^&* that normally don't occur in dictionaries.
There are three results from comparing two strings s1 and s2.
s1 comes before s2 s1 equals s2 s1 comes after s2
That is reflected in the return value of the compareTo() method. If the result is < 0 it is case #1. If the result == 0 it is case #2. If the result is > 0 it is case #3. The magnitude of the result doesn't matter.
More specifically, "lexographically" means the ordering given by the Unicode values. Unicode assigns a integer value for each character. For letters, the Unicode values are in "alphabetical order" as described above. Unicode also specifies the ordering for punctuation marks and lower-case vs. upper-case letters.
I won't go into any more detail. If you are only using alphabetic characters, then you should think of it as comparing their order alphabetically.
Also, you shouldn't worry about the exact value that is returned. Look at the javadocs and you will see that the important part is the sign of the return value. You should check whether this return value is positive, negative, or zero to determine whether one String is "less than", "greater than", or the "equal to" another String. So in your example, the -10 indicates that "hello" is "less than" (or comes before) "how".
[ January 12, 2006: Message edited by: Layne Lund ] [ January 12, 2006: Message edited by: Layne Lund ]