问题描述
|
嗨,我有一个String的数组列表,它包含一堆数字,而我在每个\“ stage \”中都有这些数字。而在第二阶段,它仅获取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
, 用String.split()
,然后用Integer.parseInt()
解决此问题。
, 只需Integer.parseInt(voteOne.split(\" \")[stage])