For Explanation watch the video
code ::
import java.util.*;
import java.lang.*;
class Demo{
public static void main(String[] args){
String s1 = "keepp";
String s2 = "peek";
char[] ch1 = s1.toCharArray();
char[] ch2 = s2.toCharArray();
Arrays.sort(ch1);
Arrays.sort(ch2);
String ss1 = new String(ch1);
String ss2 = new String(ch2);
if(ss1.equals(ss2)){
System.out.println("anagram");
}else{
System.out.println("not anagram");
}
}
}
Top comments (0)