Check Anagram in Java
import java.io.BufferedReader;
import java.io.InputStreamReader;
class SampleTest{
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
for (int i = 0; i < N; i++) {
String num1 = br.readLine();
String num2 = br.readLine();
char[] charNum1 = num1.toCharArray();
char[] charNum2 = num2.toCharArray();
Arrays.sort(charNum1);
Arrays.sort(charNum2);
if(Arrays.equals(charNum1, charNum2)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}