I have an array of Strings
in Java. I need to find anagrams from the array and print them to the screen.
I am having difficulty with the part where I am supposed to compare array elements to check if they're anagrams or not. How would I do this? I would have to make a loop to go through the array obviously.
I think that I could sort the String
s and then compare them (since if they're anagrams, they would contain the same letters in the same order when sorted), but how would I unsort them to get the original word?