What does "compare two strings lexicographically" mean?
Leading from answers from @Bozho and @aioobe, lexicographic comparisons are similar to the ordering that one might find in a dictionary.
The Java String class provides the
.compareTo () method in order to lexicographically compare Strings. It is used like this
The return of this method is an
int which can be interpreted as follows:
compareTomethod is lexicographically first.
More specifically, the method provides the first non-zero difference in ASCII values.
"computer".compareTo ("comparison") will return a value of
(int) 'u' - (int) 'a' (21). Since this is a positive result, the parameter (
"comparison") is lexicographically first.
There is also a variant
.compareToIgnoreCase () which will return
"a".compareToIgnoreCase ("A"); for example.