思路:
1,遍历第一个字符串,统计各个字符出现的次数
2,遍历第二个字符串,统计各个字符出现的次数
3,判断两个字符串对应字符出现的次数是否一致
public class OptMain { public static void main(String[] args) { isSame("sdfajsodafisaf","sdfajsodafisfa"); } private static void isSame(String one ,String two){ if(one.length() != two.length()){ System.out.println("false...."); return; } int[] oneArr = new int[26]; int[] twoArr = new int[26]; for (char c : one.toCharArray()) { int i = c - 'a'; oneArr[i]++; } for (char c : two.toCharArray()) { int i = c - 'a'; twoArr[i]++; } int loop = Math.min(oneArr.length,one.length()); for (int i = 0; i < loop; i++) { if(oneArr[i] != twoArr[i]){ System.out.println("不匹配...."); return; } } System.out.println("匹配"); } }