Thursday, 19 June 2014

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

public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
Tests if two string regions are equal. A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent character sequences that are the same. Case is ignored if ignoreCase is true.

The result of the operation is false if
    1. toffset is negative.
    2. ooffset is negative.
    3. toffset+len is greater than the length of this String object.
    4. ooffset+len is greater than the length of the other argument.

Parameters Meaning
ignoreCase - if true, ignore case when comparing characters.
toffset - the starting offset of the subregion in this string.
other - the string argument.
ooffset - the starting offset of the subregion in the string argument.
len - the number of characters to compare.

class StringRegionMatches{
 public static void main(String args[]){
  String s1 = "DEFGHIJKLMN";
  String s2 = "defghijklmn";
  
  System.out.println(s1.regionMatches(false, 2, s2, 2, 5));
  System.out.println(s1.regionMatches(true, 2, s2, 2, 5));
  System.out.println(s1.regionMatches(true, 2, s2, 3, 5));
 }
}

Output
false
true
false




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment