TUTORIALS

Java Program example to demonstrate String compareToIgnoreCase method

Written By: Chaitra M
Created at: 28-June-2023 20:36:19
Modified at: 28-June-2023 20:36:39

Program


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
Article Tags:
  • Strings
There are no likes. Be the first one to like
Likes: 0
Comments: 0