RegionMatches

Java-RegionMatches

RegionMatches

The regionMatches () method of String compares a specific region inside a string with another specific region in another string. There is an overloaded form that allows you to ignore case in such comparisons. It has two forms:

RegionMatches

For both versions, ‘toffset’ specifies the index at which the region begins within the invoking String object. The String being compared is specified by ‘other’. The index at which the comparison will start within ‘other’ is specified by ‘ooffset’. The length of the substring being compared is passed in ‘len’. In the second version, if ignoreCase is true, the case of the characters is ignored. Otherwise, case is significant. For examples:

RegionMatches


Program

RegionMatches


Program Source

public class Javaapp {

    public static void main(String[] args) {

        String str = "ABCDEFGHIJ";
        if (str.regionMatches(3, "XXDEFYY", 2, 3)) {
            System.out.println("Both regions are same");
        }else{
            System.out.println("Both regions are different");
        }
    }
}

2 thoughts on “Java-RegionMatches

Leave a Comment