I am interested in returning an int[][] via passing non-null parameters of single and dual ArrayLists to a class method, such as:
//outer loop
ArrayList<ArrayList<Integer>> rowsInMatrixA;
//inner loop
ArrayList<Integer> colsInMatrixA;
using only native Java. I have searched high and low here, in Java API, Java tutorials, and many other places. All ideas and suggestions welcome.
EDIT: here's what I've tried:
public static int[][] convertIntegers(ArrayList<ArrayList<Integer>> rows, ArrayList<Integer> cols)
{
int[][] newMatrix = new int[rowsInMatrixA.size()][colsInMatrixB.size()];
//iterate outer, through rows
for (int i=0; i < newMatrix.length; i++)
{
//iterate inner, through columns
for(int j = 0; j < newMatrix[0].length; j++){
newMatrix[i][j] = rows.get(i).get(j);
}
}
return newMatrix;
}
it still doesn't work: I get an IndexOutOfBoundsException on this line when I compile and try to get a printout in main:
newMatrix[i][j] = rows.get(i).get(j);
How can this be resolved? I would appreciate any help. Thanks.