Java String regionMatches() method example

HQ » Java Tutorial » java.lang » String » regionMatches() method example
Java String regionMatches() method example 2018-02-19T12:59:29+00:00

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 :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.