Java regionMatches () method
regionMatches () method for detecting a region within two strings are equal.
grammar
public boolean regionMatches(int toffset, String other, int ooffset, int len) 或 public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
parameter
ignoreCase - If true, the comparison character ignore case.
toffset - the starting offset this string neutron region.
other - the string argument.
toffset - the starting offset string parameter neutron region.
len - Number of characters to compare.
return value
If you specify a sub-region of the string matches the string parameter specifies the sub-region, it returns true; otherwise false. Matches exactly or consider case depends ignoreCase parameters.
Examples
public class Test { public static void main(String args[]) { String Str1 = new String("www.w3big.com"); String Str2 = new String("w3big"); String Str3 = new String("w3big"); System.out.print("返回值 :" ); System.out.println(Str1.regionMatches(4, Str2, 0, 5)); System.out.print("返回值 :" ); System.out.println(Str1.regionMatches(4, Str3, 0, 5)); System.out.print("返回值 :" ); System.out.println(Str1.regionMatches(true, 4, Str3, 0, 5)); } }
The above program execution results:
返回值 :true 返回值 :false 返回值 :true