Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串:");
String line = sc.nextLine();
char[] arr = line.toCharArray();
TreeSet<Character> ts = new TreeSet<>(new Comparator<Character>() {
@Override
public int compare(Character ch1, Character ch2) {
int num1 = ch1.compareTo(ch2);
return num1 == 0? 1: num1;
}
});
for (Character ch : arr) {
ts.add(ch);
}
for (Character ch : ts) {
System.out.print(ch);
}
}
可直接复制到main方法里,亲们觉得可以记得给个评分,每日更新 |