方法一:
package com.test;
import java.util.ArrayList;
import com.bean.Student;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import com.bean.Student;
public class qiantao_1 {
public static void main(String[] args) {
//extracted_3();
Scanner sc = new Scanner(System.in);
System.out.println("please String");
HashSet<Character> hs= new HashSet<>();
String line = sc.nextLine();
char[] arr = line.toCharArray();
for(char c: arr) {
hs.add(c);
}
for(Character ch :hs) {
}
System.out.println(hs);
}
方法二:
package com.test;
import com.bean.Student;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import com.bean.Student;
public class qiantao_1 {
public static void main(String[] args) {
//extracted_4();
ArrayList<String> list = new ArrayList<>();
list.add("a");
list.add("a");
list.add("b");
list.add("b");
list.add("b");
getSingLe(list);
System.out.println(list);
}
private static void getSingLe(List<String> list) { //定义去重方法
LinkedHashSet<String> lhs =new LinkedHashSet();
lhs.addAll(list);
list.clear();
list.addAll(lhs);
}