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

Java regionMatches() Method

Java regionMatches() Method

Java String ClassJava String class


The regionMatches() method is used to test whether two strings are equal within a region.

Syntax


public boolean regionMatches(int toffset,
                             String other,
                             int ooffset,
                             int len)

或

public boolean regionMatches(boolean ignoreCase,
                             int toffset,
                             String other,
                             int ooffset,
                             int len)

Parameters

Return Value

Returns true if the specified subregion of the string matches the specified subregion of the string argument; otherwise returns false. Whether the match is exact or case-sensitive depends on the ignoreCase parameter.

Example

Example

public

class

Test

{

   

public

static

void

main

(

String

args

[

]

)

{

       

String

Str1

=

new

String

(

"www.runoob.com"

)

;

       

String

Str2

=

new

String

(

"runoob"

)

;

       

String

Str3

=

new

String

(

"RUNOOB"

)

;

       

System

.

out

.

print

(

"Return value :"

)

;

       

System

.

out

.

println

(

Str1.

regionMatches

(

4

, Str2,

0

,

5

)

)

;

       

System

.

out

.

print

(

"Return value :"

)

;

       

System

.

out

.

println

(

Str1.

regionMatches

(

4

, Str3,

0

,

5

)

)

;

       

System

.

out

.

print

(

"Return value :"

)

;

       

System

.

out

.

println

(

Str1.

regionMatches

(

true

,

4

, Str3,

0

,

5

)

)

;

   

}

}

}

The execution result of the above program is:


返回值 :true
返回值 :false
返回值 :true

Java String ClassJava String class