import java.util.HashSet;
import java.util.Scanner;
public class Demo2 {
/**
* 存储自定义元素 , 并遍历hashSet
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
HashSet<Character> hs = new HashSet<>();
String line = sc.nextLine();
char[] c = line.toCharArray();
for (char d : c) {
hs.add(d);
}
for (Character ch : hs) {
System.out.print(ch+" ");
}
}
}
|
|