I have to write a program that counts the uniques characters in a String given by the user. For example \"abc\" returns 3 and \"aabbccd\" returns 4. I am not allow to use advan
In case you are allowed to use Java Sets, The following code is readable, compact and doing the job smoothly
public static int countUniqueChar(String word){
Set wordSet = new HashSet<>();
for(Character c : word.toCharArray())
wordSet.add(c);
return wordSet.size();
}