I would like to know what is the right way to copy two-dimension array from temporary array into original array.
The array size is unknown at the beginning of the program and user is set it later on.
here’s the code:
private static void copy_Matrix(int origin_Matrix[][] , int copy_Matrix[][], int row, int
column){
for ( int i = 0 ; i < row-1; ++i) { for (int j = 0; j < column; j++) { origin_Matrix[i][j] = copy_Matrix[i][j]; } }}
I know it’s wrong, please help..
No prefix increment necessary in Java. Also you don’t need to pass a row and column count in Java (that only leaves room for error). And, there exists a function, System.arraycopy which should be at least as efficient as copying them one at a time, if not more so.
Note that you should be aware of Java Collections (such as List/ArrayList or Vector) and consciously decide that the slight performance gains of an array of ints is necessary in your case, over the additional readability and convenience that the Collections provide.