How to check if a String equal to another String in a case insensitive manner with Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str1 = "Java";
        String str2 = "JAVA";
 
        if (str1.toLowerCase().equals(str2.toLowerCase())) {
            System.out.println("str1 is equal to str2");
        }
    }
}
  
  
  
  
  
/*
run:
       
str1 is equal to str2

*/

 



answered Oct 16, 2023 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        String str1 = "Java";
        String str2 = "JAVA";
 
        if (str1.equalsIgnoreCase(str2)) {
            System.out.println("str1 is equal to str2");
        }
    }
}
  
  
  
  
  
/*
run:
       
str1 is equal to str2

*/

 



answered Oct 16, 2023 by avibootz

Related questions

...