string regionmatches
时间: 2023-10-03 08:10:38 浏览: 39
The regionMatches method in Java is used to check if a substring of one string matches with a substring of another string. It has the following syntax:
public boolean regionMatches(int toffset, String other, int ooffset, int len)
where,
- toffset: the starting index of the substring in the calling string
- other: the string to be compared with the calling string
- ooffset: the starting index of the substring in the other string
- len: the length of the substring to be compared
The method returns true if the specified regions of the two strings match, otherwise it returns false.
Example:
String str1 = "Hello World";
String str2 = "Hello Java";
boolean result = str1.regionMatches(0, str2, 0, 5);
System.out.println(result); // Output: true (because the first 5 characters in both strings are the same, i.e., "Hello")