Check for Anagram
import java.util.Arrays;
public class CheckAnagram{
public static void main(String args[]) {
boolean ans = iAnagram("programming", "prgoramgmin");
System.out.println(ans);
}
public static boolean iAnagram(String word, String anagram){
char[] charFromWord = word.toCharArray();
char[] charFromAnagram = anagram.toCharArray();
Arrays.sort(charFromWord);
Arrays.sort(charFromAnagram);
return Arrays.equals(charFromWord, charFromAnagram);
}
}
Comments
Post a Comment