Table of Contents
String’s equalsIgnoreCase method is similar to equals method but it ignores case. So if Strings have different cases, then also it will considered as equals.
For example:
1 2 3 4 |
String str1="Java2blog.com" String str2="JAVA2BLOG.COM" |
str1.equalsIgnoreCase(str2) will return true.
Method Signature:
1 2 3 |
public boolean equalsIgnoreCase(Object anObject) |
String equalsIgnoreCase Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package org.arpit.java2blog; public class StringEqualsExamplesMain { public static void main(String[] args) { String str1 = "Hello world from java2blog.com"; String str2 = new String("Hello world from java2blog.com"); String str3 = "Hello world from JAVA2BLOG.COM"; if (str1.equalsIgnoreCase(str2)) { System.out.println("1st and 2nd Strings are equal"); } else { System.out.println("1st and 2nd Strings are not equal"); } if (str1.equalsIgnoreCase(str3)) { System.out.println("1st and 3rd Strings are equal"); } else { System.out.println("1st and 3rd Strings are not equal"); } } } |
1 2 3 4 |
1st and 2nd Strings are equal 1st and 3rd Strings are equal |
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.