public class Test1 {
public static void main(String[] args) {
String a = "0_11_16_17_18_";
String b = "";
// 获取循环次数
int fromIndex = 0;
int count = 0;
while(true){
int index = a.indexOf("_", fromIndex);
if(-1 != index){
fromIndex = index + 1;
count++;
}else{
break;
}
}
// 将字符串拆分
for (int i = 0; i < count-1; i++) {
b = a;
a = a.substring(0, a.lastIndexOf("_"));
b = b.substring(a.lastIndexOf("_"), b.lastIndexOf("_"));
System.out.println(b.replace("_", ""));
}
}
}