Question: 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

Answer: 
In Java arrays are objects. You can use the `clone()` method to copy your array. It will perform a shallow copy - it will work fine with your `int` array.

```
int [][] arr = new int[tiles.length][];
for(int i = 0; i < tiles.length; i++)
    arr[i] = tiles[i].clone();

```

1. [copy a 2d array in java](https://stackoverflow.com/questions/1686425/copy-a-2d-array-in-java)
You haven't copied the array, you've only copied a reference to the array. Both variables are referring to the same array. See this question to make a deep copy of the array: [How do I do a deep copy of a 2D array in Java?](https://stackoverflow.com/questions/1564832/how-do-i-do-a-deep-copy-of-a-2d-array-in-java)