How do I compare string regardless of their case?

Here is an example of comparing two strings for equality without considering their case sensitivity. To do this we can use equalsIgnoreCase() method of the String class. Let’s see an example below:

package org.kodejava.example.basic;

public class EqualsIgnoreCase {
    public static void main(String[] args) {
        String uppercase = "ABCDEFGHI";
        String mixed = "aBCdEFghI";

        // To compare two string equality regarding it case use the
        // String.equalsIgnoreCase method.
        if (uppercase.equalsIgnoreCase(mixed)) {
            System.out.println("Uppercase and Mixed equals.");
        }
    }
}

Wayan

Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA. Support me by donating >> here <<.

Leave a Reply