0

I need to copy a multi-dimensional array and put the copies in new objects. The original array will still be in use.

{...
     thisConstructor (myValuableArray)  ....}   // calling constructor

public thisConstructor (int[][] argArray) {

  int[][] hopefullyCopy = argArray;
}

is myValuableArray safe?

I understand Java passes parameters by value but I am not clear on the meaning.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
vv111y
  • 13
  • 5

1 Answers1

0

It is not safe from mutations applied outside the class.

You will need to take a deep copy of the array in your constructor to do that. See How do I do a deep copy of a 2d array in Java?

Community
  • 1
  • 1
Andy Turner
  • 137,514
  • 11
  • 162
  • 243