嘿傢伙我有一些困難,這是我想要的字符串數組值複製到新的字符串數組 例如:如何複製字符串數組
String[][] array = new String[3][2];
array[0][0] = "hello";
array[0][1] = "1";
array[1][0] = "guys";
array[1][1] = "2";
array[2][0] = "good ";
array[2][1] = "3";
array = new String [5][2];
all the value in the first array to be copied
array[3][0] = "";
array........;
也許你們可以幫助我如何複製所有的值進入新的字符串數組感謝
我已經嘗試這種方法,但它讓我給空指針的問題,每當我要插入新的價值:
String[][] array = new String[3][2];
array[0][0] = "olo";
array[0][1] = "ada ";
array[1][0] = "apa";
array[1][1] = "dengan";
array[2][0] = "si ";
array[2][1] = "carlo";
String[][] newArray = new String[5][2];
newArray = Arrays.copyOf(array, 5);
array = new String[5][2];
array = Arrays.copyOf(newArray, 5);
array[3][0] = "lo";
array[3][1] = "gw";
array[4][0] = "end";
array[4][1] = "ennnnnd";
for (int r = 0; r < array.length; r++) {
for (int c = 0; c < array[r].length; c++) {
System.out.print(" " + array[r][c]);
}
System.out.println("");
}
比ks
如果我想的是具有相同名稱的兩個數組有沒有辦法做到這一點?感謝 – Carlo
你可以將它複製到一個新陣列中。然後做'array = newarray'。複製你需要能夠引用來源和目的地,如果他們都被稱爲相同,它可能會得到三輪車 –