next up previous
Next: Note on comparisons: equality Up: Unit 05 Previous: Note on comparisons: equality

Note on comparisons: lexicographic comparison between strings

A string s precedes a string t in lexicographic order if

Note: For the characters that are alphabetical letters, the character order coincides with the alphabetical order. Digits precede letters, and uppercase letters precede lowercase ones.

Example:

To verify whether a string precedes another one in lexicographic order, we use the compareTo() method. Given two strings s and t, s.compareTo(t) returns


next up previous
Next: Note on comparisons: equality Up: Unit 05 Previous: Note on comparisons: equality