Java String regionMatches() Method Example

There are two types of regionMatches() methods:
  • regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)  - Tests if two string regions are equal.
  • regionMatches(int toffset, String other, int ooffset, int len)  - Tests if two string regions are equal.

Java String regionMatches() Method Example

Example to tests if two string regions are equal.
public class RegionMatchesExample {
    public static void main(String[] args) {
        String str = "javaguides";
        String subStr = "guides";
        boolean b = str.regionMatches(0, subStr, str.length(), str.length());
        boolean b1 = str.regionMatches(true, 0, str, 0, str.length());
        System.out.println(b);
        System.out.println(b1);
    }
}

Output:
false true 

Reference