JAVA简单实现不区分大小写以及空格比较字符串

import java.io.*; import java.util.*; public class Test { public static void main(String[] ags) { String s1 = "ab c k"; String s2 = "ABCK"; String s3 = "abkc" System.out.println(compare(s1, s2)); System.out.println(compare(s1, s3)); } static boolean compare(String str1, String str2) { String s1 = str1.replace(" ", ""); String s2 = str2.replace(" ", ""); return s1.equalsIgnoreCase(s2); } }

利用String类很简单的就实现了

你可能感兴趣的:(JAVA简单实现不区分大小写以及空格比较字符串)