java - Storing twodimensional array into single dimensional array -
please me fix this. want store 2 dimensional array single dimensional array possible. i'm trying have store 2 dimensional integer array created dynamically.
try this:
int[][] arr = new int[rows][cols]; int[] arr1d= new int[rows * cols]; rows = arr.length; if (rows > 0) { cols = arr[0].length; } else { cols = 0; } (int row = 0, count = 0; row < rows; row++) { (int col = 0; col < cols; col++) { arr1d[count] = arr[row][col]; count++; } }
Comments
Post a Comment