If you add a int[][] to a list, it will not add the value of the array, but the location of the array. How can I add the value of an array to a list. This is the code (This is just an example and might have small errors in it):
public class Main {
int[][] matrix = new int[2][2];
List<int[2][2]> matrixList = new ArrayList<>();
public static void main(String[] args) {
for(int i = 0; i < 4; i++){
matrixList.add(matrix);
matrix = matrixCalc(matrix);
}
for(int i = 0; i < 4; i++) {
System.out.println(Arrays.deepToString(matrixList.get(i)));
}
public int[][] matrixCalc(int[][] m){
//do various calculations with m
...
return m;
}
}
}
I want the output to have different matrixes that are calculated by the calculate method.
example of out put i want to get:
{{0,1}{5,7}}
{{2,0}{2,4}}
{{8,1}{4,8}}
{{3,3}{7,9}}
output I would get this way (WRONG!)
{{3,3}{7,9}}
{{3,3}{7,9}}
{{3,3}{7,9}}
{{3,3}{7,9}}