regionMatches method matches two strings, it matches the characters of second string with the characters of the first string from the point defined in the syntax. The string comparison start from the
str1 :name of the string with which to compare the second strnig
regionMAtches::: keyword
4 : it is the starting index of first index, from where to start matching the region of str1 with the region of str2..
str2: name of the second string whose region we have to match with first string str1
4: is the startring index of second string, matching of second string with first string str1 will start from this starting index number that is 4
7 : is the number of characters from starting index number of second string,, the starting index of str2 is 4, then the the region will be compared upto 10 more characters.
true: is for case senstivity..
import java.io.*;
public class RegionM
{
public static void main(String args[])
{
String str1=new String("Gurpreet Singh");
String str2=new String("Manpreet Singh");
String str3=new String("Gurinder singh");
System.out.println("comparing str1 and str2"+str1.regionMatches(4,str2,4,7));
System.out.println("comparing str2 and str3"+str2.regionMatches(true,3,str3,3,7));
}
}
Description of regionMatches() method:
str1. regionMatches ( 4 , str2 , 4 , 7 )str1 :name of the string with which to compare the second strnig
regionMAtches::: keyword
4 : it is the starting index of first index, from where to start matching the region of str1 with the region of str2..
str2: name of the second string whose region we have to match with first string str1
4: is the startring index of second string, matching of second string with first string str1 will start from this starting index number that is 4
7 : is the number of characters from starting index number of second string,, the starting index of str2 is 4, then the the region will be compared upto 10 more characters.
true: is for case senstivity..
Program for regionMatches() :
public class RegionM
{
public static void main(String args[])
{
String str1=new String("Gurpreet Singh");
String str2=new String("Manpreet Singh");
String str3=new String("Gurinder singh");
System.out.println("comparing str1 and str2"+str1.regionMatches(4,str2,4,7));
System.out.println("comparing str2 and str3"+str2.regionMatches(true,3,str3,3,7));
}
}