I need to check in Java if a word consists of unique letters (case insensitive). As straight solution is boring, I came up with:
- For every char in a string check if
indexOf(char) == lastIndexOf(char)
. - Add all chars to
HashSet
and check if set size == string length. - Convert a string to a char array, sort it alphabetically, loop through array elements and check if
c[i] == c[i+1]
.
Currently I like #2 the most, seems like the easiest way. Any other interesting solutions?