We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Anagrams
You are viewing a single comment's thread. Return to all comments →
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.