Java String regionMatches()方法有两个变体,可用于测试两个字符串区域是否相等。
语法
以下是此方法的语法 -
public boolean regionMatches(boolean ignoreCase,
int toffset,
String other,
int ooffset,
int len)
参数ignoreCase - 指示是否忽略大小写。
toffset - 此字符串中子区域的起始偏移量。
other - 字符串参数。
offset - 字符串参数中子区域的起始偏移量。
len - 要比较的字符数。
返回值
如果此字符串的指定子区域与字符串参数的指定子区域匹配,则返回true;否则返回false。匹配是精确匹配还是不区分大小写取决于ignoreCase参数。
示例import java.io.*;
public class Test {
public static void main(String args[]) {
String Str1 = new String("Welcome to Yiibai.com");
String Str2 = new String("YIIBAI");
System.out.print("Return Value(ignoreCase=true):");
System.out.println(Str1.regionMatches(true, 11, Str2, 0, 6));
System.out.print("Return Value(ignoreCase=false):");
System.out.println(Str1.regionMatches(false, 11, Str2, 0, 6));
}
}
执行上面示例代码,得到以下结果:
Return Value(ignoreCase=true):true
Return Value(ignoreCase=false):false
¥ 我要打赏
纠错/补充
收藏
加QQ群啦,易百教程官方技术学习群
注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。