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
Using Java 8 you could do the following:
public static long countUniqueCharacters(String input) { return input.chars() .distinct() .count(); }
This creates an IntStream of chars, then takes only distincts values and then counts the number of occurences.
IntStream
char