java.lang.String.regionMatches(int toffset, String other, int ooffset, int len)%uA0测试方法如果两个字符串的区域都是相等。这个String对象的子字符串进行比较其他的子串参数。
其结果是true,如果这些子代表相同的字符序列。这个String对象的字符串进行比较始于索引toffset和长度为len。其他的子字符串进行比较始于索引offset和长度为len。
声明
以下是java.lang.String.regionMatches()方法的声明
public boolean regionMatches(int toffset, String other, int ooffset, int len)
参数
-
toffset%uA0-- the starting offset of the subregion in this string.
-
other%uA0-- 字符串参数。
-
ooffset%uA0-- 在字符串参数的分区域的起始偏移量。
-
len%uA0-- 用来比较的字符数。
返回值
如果此字符串指定分区的字符串参数,指定的分区完全匹配此方法返回true,否则返回false。
异常
-
NA
例子
下面的例子显示java.lang.String.regionMatches()方法的使用。
package com.yiibai import java.lang.* public class StringDemo { public static void main(String[] args) { String str1 = "Collection of tutorials" String str2 = "Consists of different tutorials" /* matches characters from index 14 in str1 to characters from index 22 in str2 considering same case of the letters.*/ boolean match1 = str1.regionMatches(14, str2, 22, 9) System.out.println("region matched = " + match1) // considering different case, will return false str2 = "Consists of different Tutorials" match1 = str1.regionMatches(14, str2, 22, 9) System.out.println("region matched = " + match1) } }
让我们编译并运行上述程序,这将产生以下结果:
region matched = true region matched = false