java.lang.String regionMatches()

Description :

This java tutorial shows how to use the regionMatches() method of String class. This method returns a boolean value true or false. This is generally tests if two string region are equal. To put it simple we are comparing two strings out of the substrings of those string sources.

Method Syntax :

Below are the two overloaded method of regionMatches().

Method 1:

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

Method 2:

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

Parameter input :

 

DataType Parameter Description
int offset this String subregion starting offset
String other the string parameter argument
int ooffset the parameter regions starting offset
int len this is the number of characters we intended to compare
boolean ignorecase this is a flag telling the method if we want to compare the region regardless of case

 

Method Returns :

This method returns a boolean datatype. true if the character region matches the specified region of the string parameter.

Exception :

No Exception is expected as specified on java api.

Java Code Example :

This example source code demonstrates the use of regionMatches() method of String class.

Sample Output :

Running the regionMatches() example source code will give you the following output

java string regionMatches method example

java string regionMatches method example

Exception Scenario :

No Exception on Java API

Suggested Reading List :