import java.util.*; public class Main { public static void main(String[] args) { String str1 = "sateesh"; String str2 = "hseetas"; //Checking for the length of strings if (str1.length() != str2.length()) { System.out.println("Both the strings are not anagram"); } else { //Converting both the arrays to character array char[] ch1 = str1.toCharArray(); char[] ch2 = str2.toCharArray(); //Sorting the arrays using in-built function sort () Arrays.sort(ch1); Arrays.sort(ch2); //Comparing both the arrays using in-built function equals () if(Arrays.equals(ch1, ch2) == true) { System.out.println("Both the strings are anagram"); } else { System.out.println("Both the strings are not anagram"); } } } }
Both the strings are anagram