regionMatches() In Java Example
Chapter:
String Handling
Last Updated:
10-06-2016 19:12:40 UTC
Program:
/* ............... START ............... */
public class JavaRegionMatchExample {
public static void main(String args[]) {
String str1 = new String("Hello, How are you");
String str2 = new String("How");
String str3 = new String("HOW");
System.out.print("Result of Test1: ");
System.out.println(str1.regionMatches(7, str2, 0, 3));
System.out.print("Result of Test2: ");
System.out.println(str1.regionMatches(7, str3, 0, 3));
System.out.print("Result of Test3: ");
System.out.println(str1.regionMatches(true, 7, str3, 0, 3));
}
}
/* ............... END ............... */
Output
Result of Test1: true
Result of Test2: false
Result of Test3: true
Notes:
-
regionMatches has two variants which can be used to test if two string regions are equal.
- Syntax : public boolean regionMatches(int toffset, String other, int ooffset, int len).
- 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.
Tags
regionMatches(), Java