logo
Java CompareTo(string anotherstring) and compareToIgnoreCase
CompareTo (string anotherstring) and compareToIgnoreCase() :
1) By using compareTo() we are comparing two strings character by character such type of checking is called lexicographically checking or dictionary checking. 

2) compareTo() is return three values as outcome
a. zero (if both are equal)
b. positive (first string first character is having big character compare to second string )
c. negative(first string first character small character compare to second String ) 

3) compareTo() method comparing two string with case sensitive. 

4) By using above method we are comparing two strings character by character by ignoring case.
String CompareTo progam
class sup 
{ 
public static void main(String... ratan) 
{ 
String str1="ramana"; 
String str2="freetimelearn"; 
String str3="Ramanareddy"; 
String str4="RAMANA"; 
String str5="FREETIMELEARN"; 
System.out.println(str1.compareTo(str2)); 
System.out.println(str1.compareTo(str4)); 
System.out.println(str2.compareTo(str4)); 
System.out.println(str4.compareTo(str2)); 
System.out.println(str1.compareTo(str4)); 
System.out.println(str1.compareTo(str5)); 
System.out.println(str1.compareToIgnoreCase(str4)); 
System.out.println(str2.compareToIgnoreCase(str4)); 
System.out.println(str1.compareToIgnoreCase(str3)); 
} 
};
Output :
16, 32, 16, -16, 32, 48, 0, -16, -5