Java String RegionMatches() Method



This method has two variants that can be used to test if two string regions are equal.


Here is the syntax of this method:

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


Here is the detail of parameters −

  • toffset − the starting offset of the subregion in this string.
  • other − the string argument.
  • ooffset − the starting offset of the subregion in the string argument.
  • len − the number of characters to compare.

Return Value

  • It returns true if the specified subregion of this string matches the specified subregion of the string argument; false otherwise. Whether the matching is exact or case insensitive depends on the ignoreCase argument.


import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str1 = new String("Welcome to intellinuts.com");
      String Str2 = new String("Intelli");
      String Str3 = new String("INTELLI");

      System.out.print("Return Value :" );
      System.out.println(Str1.regionMatches(11, Str2, 0, 9));

      System.out.print("Return Value :" );
      System.out.println(Str1.regionMatches(11, Str3, 0, 9));

This will produce the following result:


Return Value :true
Return Value :false

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.