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
Stringstr1="Java2blog.com"
Stringstr2="JAVA2BLOG.COM"
str1.equalsIgnoreCase(str2) will return true.
Method Signature:
1
2
3
publicbooleanequalsIgnoreCase(ObjectanObject)
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
packageorg.arpit.java2blog;
publicclassStringEqualsExamplesMain{
publicstaticvoidmain(String[]args){
Stringstr1="Hello world from java2blog.com";
Stringstr2=newString("Hello world from java2blog.com");
Stringstr3="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");
}
}
}
When you run above program, you will get below output:
1
2
3
4
1stand2ndStrings are equal
1stand3rdStrings 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.