The compareTo() method is used to compare two strings lexicographically, and to know which string is bigger or smaller. Each character of both the strings is converted into a Unicode value for comparison. This should be used as: s1.compareTo(s2). The character sequence represented by this String object (s1) is compared lexicographically to the character sequence represented by the argument string (s2). This method returns integer value like:
Zero: if s1 is equal to s2, then this method returns zero.
Positive value: if s1 is greater than s2, then this method returns positive integer value.
Negative value: if s1 is smaller than s2, then this method returns negative value.