Java equalsIgnoreCase() Method
The equalsIgnoreCase() method is used to compare a string with a specified object, ignoring case differences.
Syntax
public boolean equalsIgnoreCase(String anotherString)
Parameters
-
anObject -- The object to compare with the string.
Return Value
Returns true if the given object is equal to the string; otherwise returns false.
Example
equals() distinguishes case differences, while equalsIgnoreCase() does not:
Example
public
class
Test
{
public
static
void
main
(
String
args
[
]
)
{
String
Str1
=
new
String
(
"runoob"
)
;
String
Str2
=
Str1
;
String
Str3
=
new
String
(
"runoob"
)
;
String
Str4
=
new
String
(
"RUNOOB"
)
;
boolean
retVal
;
retVal
=
Str1.
equals
(
Str2
)
;
System
.
out
.
println
(
"Return value = "
retVal
)
;
retVal
=
Str3.
equals
(
Str4
)
;
System
.
out
.
println
(
"Return value = "
retVal
)
;
retVal
=
Str1.
equalsIgnoreCase
(
Str4
)
;
System
.
out
.
println
(
"Return value = "
retVal
)
;
}
}
The execution result of the above program is:
返回值 = true
返回值 = false
返回值 = true
Java String class