Well my solution may not be the best here ,
From your question , what i've understood is that basically you want to get all the numbers from a string builder and put it in an integer array.
So here goes ,
Firstly you may want to get a string from the string builder.
String myString = mystringbuilder.toString();
This string now contains your numbers with spaces.
now use the following ,
String[] stringIntegers = myString.split(" "); // " " is a delimiter , a space in your case
This string array now contains your integers at positions starting from 0 .
Now , you may want to take this string array and parse its values and put it in an ArrayList.
This is how it's done ,
ArrayList<Integer> myIntegers = new ArrayList<Integer>();
for(int i = 0; i<stringIntegers.length;i++){
myIntegers.add(Integer.parseInt(stringIntegers[i]));
}
now your myIntegers arraylist is populated with the needed integers , let me break it down for you.
- You create an array for the integers.
- There's a for loop to cycle through the string array
- In this for loop for every position of the string array you convert the string at that position to an integer with Integer.parseInt(String);
- Then , you just add it to the arraylist we created.
COMPLETE CODE:
String mynumbers = stringBuilder.toString();
String[] stringIntegers = mynumbers.split(" ");
ArrayList<Integer> myIntegers = new ArrayList<Integer>();
for(int i=0;i<stringIntegers.length;i++){
myIntegers.add(Integer.parseInt(stringIntegers[i]));
}