anagram java program
import java.util.Arrays;
public class StringAnagramProgram
{
public static void main(String[] args)
{
String strOne = "Silent";
String strTwo = "Listen";
strOne = strOne.toLowerCase();
strTwo = strTwo.toLowerCase();
// checking if two strings length are same
if(strOne.length() == strTwo.length())
{
// converting strings to char array
char[] charOne = strOne.toCharArray();
char[] charTwo = strTwo.toCharArray();
// sorting character array
Arrays.sort(charOne);
Arrays.sort(charTwo);
// if sorted character arrays are same then the string is anagram
boolean output = Arrays.equals(charOne, charTwo);
if(output)
{
System.out.println(strOne + " and " + strTwo + " are anagram.");
}
else
{
System.out.println(strOne + " and " + strTwo + " are not anagram.");
}
}
else
{
System.out.println(strOne + " and " + strTwo + " are not anagram.");
}
}
}