java - ArrayList to int[][] - index out of bounds exception -



java - ArrayList to int[][] - index out of bounds exception -

this question has reply here:

how convert arraylist<arraylist<integer>> int[][]? 3 answers

i interested in returning int[][] via passing non-null parameters of single , dual arraylists class method, such as:

//outer loop arraylist<arraylist<integer>> rowsinmatrixa; //inner loop arraylist<integer> colsinmatrixa;

using native java. have searched high , low here, in java api, java tutorials, , many other places. ideas , suggestions welcome.

edit: here's 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 (int i=0; < newmatrix.length; i++) { //iterate inner, through columns for(int j = 0; j < newmatrix[0].length; j++){ newmatrix[i][j] = rows.get(i).get(j); } } homecoming newmatrix; }

it still doesn't work: indexoutofboundsexception on line when compile , seek printout in main:

newmatrix[i][j] = rows.get(i).get(j);

how can resolved? appreciate help. thanks.

your declared function wrong:

it should homecoming int[][] instead of int[].

additionally, newmatrix[i] represents 1d array. can't set integers in it. utilize newmatrix[i][j] instead.

java arraylist

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -