Posted By:
Eric_Hubbard
Posted On:
Tuesday, March 22, 2005 06:05 PM
What is your inner dimension an ArrayList in the first place? You know how many columns you are going to need. Why not:
ResultSet grs = null;
ArrayList rows = new ArrayList();
while(grs.next()) {
float row[] = {grs.getFloat(1), grs.getFloat(2) };
rows.add(row);
}
Now you don't have any casts to worry about at all. And you've saved memory by not overusing ArrayList on every row.
Once you want to convert it to a float[][] you can just... and check it... your saving memory again by reusing the inner arrays from above.. just moveing pointers around and you aren't haven't to nest the loop.
float data[][] = new float[2][rows.size()];
int rowNum =0;
Iterator i = rows.iterator();
while(i.hasNext()) {
float row[] = (float[]) i.next();
data[rowNum] = row;
rowNum ++;
}
disclaimer: I didn't run it!