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

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API