开发者

Grab next numbers in a string

Hi have a arraylist of String and it contains bunch of numbers and I have g开发者_运维问答et the numbers in each "stage". And at but at the second stage it only grabs the 1 instead of 10 is there anyway I can grab the next integers in the string? I got it to work for any numbers less than 10 but after 10 it just goes off.

   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")

will return an array of Strings. Then Integer.parseInt() each of the strings. read the documentation of these 2 methods:

http://download.oracle.com/javase/6/docs/api/java/lang/String.html

http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html


Use String.split() and then Integer.parseInt() to solve this problem.


Simply Integer.parseInt(voteOne.split(" ")[stage])

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜