java - Copying matrices -
i have re-create matrix , alter new matrix, don't want alter initial one. represent them arraylist of arraylists. here code
arraylist<arraylist<integer>> tempmatrix = new arraylist<arraylist<integer>>(); for(arraylist<integer> row : matrix) { for(integer index : row) { tempmatrix.get(row).add(index); } } compiler says it's illegal utilize method purpose. else can copy?
you can re-create whole row, saving lot of trouble:
arraylist<arraylist<integer>> tempmatrix = new arraylist<arraylist<integer>>(); for(arraylist<integer> row : matrix) { tempmatrix.add(new arraylist<integer>(row)); } java arraylist
No comments:
Post a Comment