Which of the following is faster in Java? Is there any other way that is faster than any of these?
int[][] matrix = new int[50][50];
for (int k=0;k<10;k++){
// some calculations here before resetting the array to zero
for (int i = 0; i <50; i++) {
for (int j = 0; j <50; j++) {
matrix[i][j]=0;
}
}
}
Or this:
int[][] matrix = new int[50][50];
for (int k=0;k<10;k++){
// some calculations here before resetting the array to zero
matrix = new int[50][50];
}