代码
java
public static boolean isAnagram(String s,String t){
char[] x = s.toCharArray();
char[] y = t.toCharArray();
Arrays.sort(x);
Arrays.sort(y);
boolean val = Arrays.equals(x, y);
return val;
}
测试如下
java
public static void main(String[] args) {
String s = "anagram";
String t = "nagaras";
boolean val = isAnagram(s, t);
System.out.println(val);
}