Table of Contents
Method Syntax:
There are two overloaded version of regionMatches:
1 2 3 4 5 6 7 |
// Case sensitive public boolean regionMatches(int toffset, String other, int ooffset, int len): // It has extra option to ignore the case public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) |
Parameters:
ignoreCase: It is boolean field to indicate whether to ignore case or not.
toffset : It is start index of sub String of String on which this method is being called.
other: It is other String by which this String will compare.
ooffset: It is start index of substring of other argument String
len : Number of characters to compare
1 2 3 4 5 6 |
// 1st String str1= "Hello world from java2blog.com"; //2nd String str2= "Core java programming tutorials"; |
String regionMatches example :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
package org.arpit.java2blog; public class StringRegionMatchesExample { public static void main(String[] args) { // 1st String str1= "Hello world from java2blog.com"; //2nd String str2= "Core java programming tutorials"; // 3rd String str3= "JAVA PROGRAMMING TUTORIALS"; System.out.println("Comparing 1st and 2nd (java in both String): "+ str1.regionMatches(17, str2, 5, 4)); // Ignoring case System.out.println("Comparing 2nd and 3nd (programming in both string): "+ str2.regionMatches(true,10, str3, 5, 4)); } } |
1 2 3 4 |
Comparing 1st and 2nd (java in both String): true Comparing 2nd and 3nd (programming in both string): true |