赞
踩
//该方法不用在创建Set对象时做对比,而是直接采用Set中本身自由的快排
public class Test1 {
public static void main(String[] args) {
//1.键入字符串
System.out.println("请输入一串字符串");
Scanner sc = new Scanner(System.in);
//2.键入
String s = sc.next();
//转化为字符数组
char[] cha = s.toCharArray();
Set<Character> list = new TreeSet<>();
//遍历后添加到Set集合
for (int i = 0; i < cha.length; i++) {
list.add(cha[i]);
}
//增强for遍历Set集合
for (Character c : list) {
System.out.print(c);
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。