public static void main(String[] args) {
String s="1,2,2,2,2,2,3,3,3";
String[] array = s.split(",");
StringBuilder sb = new StringBuilder();
for (String str : array) {
if(sb.indexOf(str) != -1){
continue;
}
sb.append(str).append(",");
}
String newStr = sb.toString().substring(0,sb.length() - 1);
System.out.println(newStr);
}
转载于:https://www.cnblogs.com/yy123/p/4078065.html