Easy Tutorial
❮ File Date Modify Character Islowercase ❯

Java regionMatches() Method

Java String Class


The regionMatches() method is used to check if two strings are equal within a specified region.

Syntax

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

or

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

Parameters

-

ignoreCase -- If true, case is ignored when comparing characters.

-

toffset -- The starting offset of the substring in this string.

-

other -- The string argument.

-

ooffset -- The starting offset of the substring in the string argument.

-

len -- The number of characters to compare.

Return Value

Returns true if the specified substring of this string matches the specified substring of the string argument; otherwise, false. Whether the match is exact or case-insensitive depends on the ignoreCase parameter.

Example

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("www.tutorialpro.org");
        String Str2 = new String("tutorialpro");
        String Str3 = new String("tutorialpro");

        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 output of the above program is:

Return Value :true
Return Value :false
Return Value :true

Java String Class

❮ File Date Modify Character Islowercase ❯