自然排序
String str = "bcdeadferwplkou";
char[] cs = str.toCharArray();
TreeSet<Character> ts = new TreeSet<>();
for (Character value : cs) {
ts.add(value);
}
System.out.println(ts);
倒叙
String str = "bcdeadferwplkou";
char[] cs = str.toCharArray();
TreeSet<Character> ts = new TreeSet<>(new Comparator<Character>() {
@Override
public int compare(Character o1, Character o2) {
return o2.compareTo(o1);
}
});
for (Character value : cs) {
ts.add(value);
}
System.out.println(ts);
|