Deep cloning multidimensional arrays in Java...? -


this question has answer here:

i have 2 multidimensional arrays (well they're 2d) have inferred size. how deep clone them? here's have gotten far:

public foo(character[][] original){     clone = new character[original.length][];     for(int = 0; < original.length; i++)           clone[i] = (character[]) original[i].clone(); } 

a test equality original.equals(clone); spits out false. why? :|

/**creates independent copy(clone) of boolean array.  * @param array array cloned.  * @return independent 'deep' structure clone of array.  */ public static boolean[][] clone2darray(boolean[][] array) {     int rows=array.length ;     //int rowis=array[0].length ;      //clone 'shallow' structure of array     boolean[][] newarray =(boolean[][]) array.clone();     //clone 'deep' structure of array     for(int row=0;row<rows;row++){         newarray[row]=(boolean[]) array[row].clone();     }      return newarray; } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -