public static void main(String[] args) {
String str = "1231211255121";
int frontLength = 0;
while(str.contains("2")){
int index = str.indexOf("2");
System.out.println( "2出现位置"+index + frontLength + 1);
frontLength += (index + 1);
str = str.substring(index + 1);
}
System.out.println();
}