Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java equalsIgnoreCase() Method

Java equalsIgnoreCase() Method

Java String ClassJava String class


The equalsIgnoreCase() method is used to compare a string with a specified object, ignoring case differences.

Syntax


public boolean equalsIgnoreCase(String anotherString)

Parameters

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 ClassJava String class