java - Copy int array to array -


i have simple int array initialize this:

 int [][] temparray=bp.getarray();//get array other class(bp)  //doing things temparray... 

when change temparray change bp.getarray();. because referenced bp.getarray();?

yes, if want new reference it's easy, have use arrays.copyof. other functions array.clone , system.arraycopy.

arrays.copyof// java 6 feature. older versions switch system.arraycopy.      public static int[][] deepcopy(int[][] original) {         if (original == null) {               return null;         }          final int[][] result = new int[original.length][];         (int = 0; < original.length; i++) {             result[i] = arrays.copyof(original[i], original[i].length);         }         return result;     } 

this deep copy 2d array.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -