Thursday 19 June 2014

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

public boolean regionMatches(int toffset, String other, int ooffset, int len)
Tests if two string regions are equal. 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. 

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
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 StringRegionMatches1{
 public static void main(String args[]){
  String s1 = "DEFGHIJKLMN";
  String s2 = "defghijklmn";
  String s3 = "DEFGHIJKLMN";
  
  System.out.println(s1.regionMatches(2, s2, 2, 5));
  System.out.println(s1.regionMatches(2, s3, 2, 5));
 }
}

Output
false
true



 

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment