0

I have 2D array:

    int[] zero = {
        1, 1, 1, 1, 1,
        1, 0, 0, 0, 1,
        1, 0, 0, 0, 1,
        1, 0, 0, 0, 1,
        1, 0, 0, 0, 1,
        1, 0, 0, 0, 1,
        1, 1, 1, 1, 1};        

    int[][] tab = {zero, zero};

I want to change this:

tab[0][0] = 0;    

But when I did that It also change tab[1][0]. Can you tell me how can I disable that?

0

1 Answer 1

1

By making it so the two arrays are different objects rather than the same object.

One way to achieve that would be:

int[][] tab = {zero.clone(), zero.clone()};
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.