public String changeStr(List<Integer> list) {
//注释我懒的写了。。。自己看吧,代码后期有空再优化。
int a = list.get(0);
String str = a + "";
int b = a;
for (int i = 1; i < list.size(); i++) {
if (b + 1 == list.get(i)) {
b = b + 1;
int index = str.lastIndexOf("~");
int index2 = str.lastIndexOf(",");
if (index < 0) {
str = str + "~" + b;
} else {
if (index2 < 0) {
str = a + "~" + b;
} else {
if (index2 < index && index2 > 0) {
str = str.substring(0, index);
}
str = str + "~" + b;
}
}
} else {
b = list.get(i);
str = str + "," + b;
}
}
return str;
}