Java Anagrams

  • + 1 comment

    char [] arrayA = A.toLowerCase().toCharArray(); Because the question said these are case-insensitive anagrams, A.toLowerCase() will return a string that all the characters are in lower case (A.toUpperCase() is also ok). If A = "ABC", then A.toLowerCase() = "abc"

    A.toCharArray() will convert the String A to a char array. For example: Let's say A = "abc", if we do char[] arrayA = A.toCharArray(); then arrayA[0] = 'a', arrayA[1] = 'b', arrayA[2] = 'c'

    Arrays.sort(arrayA) will sort the specified array into ascending numerical order, here, the arrayA[] will be sorted

    Arrays.equals(a, b) will check if these two specified arrays are equal. Return true if yes.