Java How ToCheck Anagram Strings
Check Anagram Strings
Two strings are anagrams if they contain the same characters in a different order:
Example
import java.util.Arrays;String str1 = "listen";String str2 = "silent";char[] arr1 = str1.toCharArray();char[] arr2 = str2.toCharArray();Arrays.sort(arr1);Arrays.sort(arr2);boolean isAnagram = Arrays.equals(arr1, arr2);System.out.println(isAnagram ? "Anagram" : "Not Anagram");Explanation: We convert both strings to arrays, sort them, and check if they are equal. If yes, the strings are anagrams.

