开发者

Grab next numbers in a string

开发者 https://www.devze.com 2023-03-10 13:50 出处:网络
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 an

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

精彩评论

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