Java Program example to demonstrate String compareToIgnoreCase method
Program
public class StringCompareToIgnoreCase
{
public static void main(String[] args)
{
String str1 = "Welcome to oodlescoop";
String str2 = "Welcome to oodlescoop";
String str3 = "Hello all";
String str4 = "Welcome to oodlescoop tutorials";
String str5 = "WELCOME TO OODLESCOOP";
System.out.println(str1.compareToIgnoreCase(str2) + "\t: strings are equal");
System.out.println(str1.compareToIgnoreCase(str3) + "\t: first string is greater");
System.out.println(str1.compareToIgnoreCase(str4) + "\t: second string is greater");
System.out.println(str1.compareToIgnoreCase(str5) + "\t: equal inspite of case of the text");
}
}
Output
0 : strings are equal
15 : first string is greater
-10 : second string is greater
0 : equal inspite of case of the text