a little help here. I'm so confused and have done so many variations of converting String array into int array.
I get numbers from a file then tokenize it. However, I get a NumberFormatException and a lot of errors when trying to convert the array. Any idea?
Here's my code below:
int[] intarray=new int[token.length];
int i=0;
for (String str : token){
intarray[i++] = Integer.parseInt(str);
}
Any help would be much appreciated.
[EDIT] When I do this code below. No errors but it only prints some integers in the token.
int[] ints = new int[arrays.length];
for(int i=0; i<array.length; i++){
try{
ints[i] = Integer.parseInt(array[i]);
}
catch(NumberFormatException nfe){
//Not an integer, do some
}
}
Here's the txt file where I get the numbers:
3 5
1 2 1
2 4 2
3 1 2
6 2 3
4 9 1
[SOLVED] I got it. Simply split("\W+"). I thought splitting " " is enough to also split newline. Thanks guys.