this is what i have so far, i need to convert this string array into just an array of integers, the string array looks something like this
wholef[0] = "2 3 4";
wholef[1] = "1 3 4";
wholef[2] = "5 3 5";
wholef[3] = "4 5 6";
wholef[4] = "3 10 2";
these values come from a text file that i read from but now i need to convert this into one big array of integers, im trying to use the split method but im not sure if it will work on this kind of setup. if anyone can give me a better way it would be nice but i just need to convert this into an array of integers, thats really all i need.
for(int k = 0; k < fline; k++)
{
String[] items = wholef[k].replaceAll(" ", "").split(",");
int[] parsed = new int[wholef[k].length];
for (int i = 0; i < wholef[k].length; i++)
{
try
{
parsed[i] = Integer.parseInt(wholef[i]);
} catch (NumberFormatException nfe) {};
}
}
This is the new code im using now, its very close cause i only get one error
int q = 0;
for (String crtLine : wholef)
{
int[] parsed = new int[wholef.length];
String[] items = crtLine.split(" ");
for (String crtItem: items)
{
parsed[q++] = Integer.parse(crtItem);
}
}
the error is this java:97: error: cannot find symbol parsed[q++} = Integer.parse(crtItem); ^ symbol: method parse(String) location: class Integer 1 error
String
s? – Boris the Spider Mar 7 at 21:18parsed[q++] = Integer.parse(crtItem)
should beparsed[q++] = Integer.parseInt(crtItem)
– nattyddubbs Mar 7 at 21:36