Java String compareToIgnoreCase method


In this program, You will learn how to implement the String compareToIgnoreCase() method in Java.


if (a.compareToIgnoreCase(b)) { 
    //statement
}

Example: How to implement String compareToIgnoreCase() method in java

import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String a, b;
        int i;

        System.out.print("Enter first string:");
        a = sc.nextLine();

        System.out.print("Enter second string:");
        b = sc.nextLine();

        i = a.compareToIgnoreCase(b);

        if (i == 0) {
            System.out.print("Strings are equal");
        } else {
            System.out.print("Strings are not equal");
        }

    }
}

Output:

Enter first string:XIITH.COM
Enter second string:xiith.com
Strings are equal