Test if to words are anagrams

public class AreAnagrams { public static boolean areAnagrams(String a, String b) { char[] aArray = a.toCharArray(); char[] bArray = b.toCharArray(); Arrays.sort(aArray); Arrays.sort(bArray); return new String(aArray).equals(new String(bArray)); } public static void main(String[] args) { System.out.println(areAnagrams("momdad", "dadmom")); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.