例如字符串
String a = "1,2,3,4,5";
String b = 3,4,5,6,7";
String purchaserNames = a.concat(",").concat(b);
String[] purchaserNamesArray = purchaserNames.split(",");
List list = Arrays.asList(purchaserNamesArray);
Set purchaserNamesSet = new HashSet(list);
purchaserNames = StringUtils.join(purchaserNamesSet, ',');
最后得到的字符串就是purchaserNames = "1,2,3,4,5,6,7";
List先转换为Array可以这样处理:
ArrayList<String> list=new ArrayList<String>();
String[] strings = new String[list.size()];
String[] a = list.toArray(strings);
注:List直接转换,list.toArray()会抛异常,编译通过,执行异常。
然后在进行上面的去重!!!