TreeSet实现去重

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Set<Character> set = new TreeSet<>();
        String s = in.nextLine();
        char[] ch = s.toCharArray();
        for(int i = 0; i<ch.length; i++){
            if((int)(ch[i]) >= 0 && (int)(ch[i]) <= 127){
                set.add(ch[i]);
            }
        }
        System.out.print(set.size());
    }
}