您好,有一个字符串数组列表,它包含一堆数字,我已经得到了每个“阶段”中的数字。但在第二阶段它只抓取 1 而不是 10 无论如何我可以抓取字符串中的下一个整数吗?我让它对小于 10 的任何数字都起作用,但在 10 之后它就消失了。
int stage = 1; // depending on where it is placed in the program it changes
String voteOne = "1 10 3 4 5 6 7 8 9 2";
char vote = voteOne.getCharAt(stage);
最佳答案
voteOne.split("\\s")
将返回一个字符串数组。然后 Integer.parseInt() 每个字符串。阅读这两种方法的文档:
http://download.oracle.com/javase/6/docs/api/java/lang/String.html
http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html
关于java - 获取字符串中的下一个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6234268/