Problem with reading numbers from file into double int array...

Okay, this is a snippet of my code:

publicvoid readMap(String file){

try{

URL url = getClass().getResource(file);

System.out.println(url.getPath());

BufferedReader in =new BufferedReader(new FileReader(url.getPath()));

String str;

String[] temp;

int j=0;

while ((str = in.readLine()) !=null){

temp = str.split(",");

for(int i=0;i<temp.length;i++){

map[j][i] = java.lang.Integer.parseInt(temp[i]);

}

j++

}

in.close();

}catch (IOException e){

System.out.println("Error: "+ e.toString());

}

}

map[][] is a double int array. Now, the code is running through each line of the text file (with each line looking like this: 0,3,6,2,2,3,1,5,2,3,5,2), and I want to put the numbers into a corresponding double int array (which is where map[][] comes in). Now, this code WOULD work, except I need to set the sizes of each array before I start adding, but I don't know how to get the exact sizes.. how can I get around this issue?

Message was edited by:

maxfarrar>

[1785 byte] By [maxfarrara] at [2007-11-26 17:51:25]
# 1

Use an ArrayList<ArrayList><Integer>> instead of map[][]. Then you don't need to know the size before processing.

After reading the file and if you absolutely need it, convert the ArrayList<ArrayList><Integer>> into an array[][]. Since JDK 1.5, you can add primitive ints into Integer containers.

hiwaa at 2007-7-9 5:03:56 > top of Java-index,Java Essentials,Java Programming...
# 2
You can do a two-dimensional ArrayList? That syntax you wrote didn't work.I tried doing:private ArrayList<ArrayList><Integer>> map;
maxfarrara at 2007-7-9 5:03:56 > top of Java-index,Java Essentials,Java Programming...
# 3

> You can do a two-dimensional ArrayList? That syntax

> you wrote didn't work.

> I tried doing:

> > private ArrayList<ArrayList><Integer>> map;

>

Your syntax is just wrong -- or, this forum software has bug in handling angle brackets.

ArrayList<ArrayList><Integer>>

...The closing angle bracket after the second 'ArrayList' is the one generated by the bug. Basically, it should be T<T<T2>> without spaces. Oh, for that matter:

Arraylist<ArrayList<Integer>>

hiwaa at 2007-7-9 5:03:56 > top of Java-index,Java Essentials,Java Programming...
# 4
Okay, with that, how do I pull, say, the item at 3, 3?
maxfarrara at 2007-7-9 5:03:56 > top of Java-index,Java Essentials,Java Programming...
# 5
> Okay, with that, how do I pull, say, the item at 3, 3?Assuming 3 means fourth element ...int n = map.get(3).get(3); // 'map' is an ArrayList of ArrayList<Integer>
hiwaa at 2007-7-9 5:03:56 > top of Java-index,Java Essentials,Java Programming...