Java menghitung karakter unik dalam string

import java.util.*;
 
public static int countUniqueCharacters(String string) {
    // Hash set to store the unique characters of the given string
    HashSet<Character> characters = new HashSet<>();

    // Inserts every character of the string into the hash set
    // Duplicates won't be added twice
    for (int i = 0; i < string.length(); i++) {
        characters.add(string.charAt(i));
    }

    // Returns the size of the has set
    return characters.size();
}
Courageous Cottonmouth