在Java中,我们如何复制一个3-D数组? 事情是,当我们使用new_array.clone()
或类似的东西时,我们将条目地址放入another_array中,而不是实际值。 因此,当我清除()old_array
,new_array
是空太在java中复制多维数组
private List<List<List<String>>> moves = new ArrayList<List<List<String>>>();
private List<List<List<String>>> moves1 = new ArrayList<List<List<String>>>();
.blah
.blah
.blah
mid_array = new ArrayList<List<String>>();//will use this array to insert inot moves1
for(int f = 0; f < moves.size(); f++)//make a copy of original array.
{
List<String> row_st = moves.get(f).get(0);
List<String> deck_st = moves.get(f).get(1);
mid_array.add(row_st);//current array of the Rows
mid_array.add(deck_st);//current array of the Deck
moves1.add(mid_array);
System.out.println("Moves1 "+moves1);//displays the new array correctly
mid_array.clear();//clear mid_array, NOT moves1 or moves arrays
System.out.println("Moves1 "+moves1);//new array is now empty
}