可以使用 Set 集合来去重,然后再将集合中的元素转换为字符串。
String str = "a,b,c,c,d,e,e,f"; String[] arr = str.split(","); Set<String> set = new HashSet<String>(Arrays.asList(arr)); String result = String.join(",", set); System.out.println(result);
结果
a,b,d,c,e,f
标签:arr,set,分隔,String,逗号,Set,result,字符串 From: https://www.cnblogs.com/jk200/p/17490759.html