在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
}