here i want to make duplicate array "arr" for my tile array and make some changes to it, the problem is when i make the changes (in method neighbors) it applies to the original array "tiles" too
public class Board {
private final int [][] tiles;
// construct a board from an n-by-n array of blocks
// (where blocks[i][j] = block in row i, column j)
public Board(int[][] blocks) {
tiles = blocks;
}// all neighboring boards
public Iterable<Board> neighbors() {
Queue<Board> q = new LinkedList<>();
int [][] arr = tiles;
// do stuff
if (y+1 < n) {
int t = arr[x][y];
arr[x][y] = arr[x][y+1];
arr[x][y+1] = t;
Board br = new Board(arr);
if(!this.equals(br)) {
q.add(new Board(arr));
}
}
return q;
}
}
thanks for your time