Hey guys this is a followup to my previous question. I now have a text file which is formatted like this:
100 200
123
124 123 145
What I want to do is get these values into a two dimensional ragged array in Java. What I have so far is this:
public String[][] readFile(String fileName) throws FileNotFoundException, IOException {
String line = "";
ArrayList rows = new ArrayList();
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
while((line = br.readLine()) != null) {
String[] theline = line.split("\\s");//TODO: Here it adds the space between two numbers as an element
rows.add(theline);
}
String[][] data = new String[rows.size()][];
data = (String[][])rows.toArray(data);
//In the end I want to return an int[][] this a placeholder for testing
return data;
My problem here is that for example for the line 100 200 the variable "theline" has three elements {"100","","200"}
which it then passes on to rows with rows.add(theline)
What I want is to have just the numbers and if possible how to convert this String[][] array into an int[][] array int the end to return it.
Thanks!