Java String compareToIgnoreCase() method


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


if (a.compareToIgnoreCase(b)) { }


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

Run it Now
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("\nEnter Second string :");
        b = sc.nextLine();

        i = a.compareToIgnoreCase(b);

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

    }
}

Output:

Enter First string :PytHoN
Enter Second string :python
Both Strings are equal