我需要计算字符串中的项目数并分别显示它们中的每一个,例如 1) --- 2) ---- 但代码无法正常工作,
public static void main(String[] args) {
String forms = "[436,43,4,900,703,483,......]"; << a long list
int counter = 0;
int index =0;
String temp = "";
for(int i=0; i<=forms.length();i++)
{
index = forms.indexOf(",");
temp = forms.substring(0, index+1);
System.out.println(i + ") " + temp);
forms = forms.replace(temp,"");
counter++;
}
System.out.println("Counter" + counter);
}
结果显示代码通过字符串,但只是到它的中间。它有大约700个项目。但它显示只有 350 个项目。