将数组这个的重复元素获取出来 在去重
public static void main(String[] args) { String str = "xx@xx.com,aa@aa.com,aa@aa.com,nn@aa.com,xx@aa.com,xx@xx.com" String[] arr = str.split(",") System.out.println("arr: " + arr); //arr: [xx@xx.com, aa@aa.com, aa@aa.com, nn@aa.com, xx@aa.com, xx@xx.com] Set listAll = new LinkedHashSet<String>()
// 获取数组重复的元素 for (int i = 0; i < arr.length; i++) { //System.out.println("arr: " + arr[i]); int curr = i; for (int j = 0; j < arr.length; j++) { if (arr[j] == arr[i] && i != j) { // System.out.println("solution1: " + arr[i]) listAll.addAll(arr[i]) } } } System.out.println("listAll: " + listAll) //listAll: [xx@xx.com, aa@aa.com] } }