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);
}
时间: 2024-10-13 03:02:58