package string; public class regionMatch { public static void main(String[] args) { /** * 比较字符串的区域是否相等 */ String str1="abcdEfge"; String str2="Defge"; boolean match1 =str1.regionMatches(4, str2, 1, 3);//第一个参数表示从几个字符开始,第二个参数要比较的字符串,第三个参数要比较字符串开始的位置,第四个参数要比较的区域 boolean match2=str1.regionMatches(true, 4, str2, 1, 3);//true表示不区分大小写 System.out.println(match1); System.out.println(match2); } }
输出结果