Two words are anagrams when they contain the same letters in the same counts, like listen and silent. Sorting both and comparing is simple, while counting letters gives a faster O(n) check. Use the counting approach when the alphabet is small, such as lowercase letters only. For grouping many words into anagram sets, a HashMap keyed by the sorted word is the usual tool.