exampracticeonline.com
String compareTo()

String comparison

In java, String comparison is done like dictionary. If a string 'str1' comes before another string 'str2' in dictionary, then str2 is said to be greater than 'str1' in string comparison.

str1 > str2 – ‘str1’ comes after ‘str2’ in dictionary. So, in Java comparison return positive value and str1 also comes after str2.
str1 < str2 - 'str1' comes before 'str2' in dictionary. So, in Java comparison return negative value and str1 also comes before str2.
str1 = str2 - 'str1' and 'str2' are equal. So, in Java comparison return 0 value and str1 is equal to str2.

Java String compareTo()

The java string compareTo() technique contrasts the given string and current string lexicographically. It returns positive number, negative number or 0. 

It thinks about strings based on Unicode estimation of each character in the strings. 

In the event that first string is lexicographically more prominent than second string, it returns positive number (distinction of character esteem). On the off chance that first string is not exactly second string lexicographically, it returns negative number and if first string is lexicographically equivalent to second string, it returns 0.

 

if str1 > str2, it returns positive number  
if str1 < str2, it returns negative number  
if str1 == str2, it returns 0