clone二維數組
char[][]a = {{'.','.','9','7','4','8','.','.','.'},{'7','.','.','.','.','.','.','.','.'},{'.','2','.','1','.','9','.','.','.'},{'.','.','7','.','.','.','2','4','.'},{'.','6','4','.','1','.','5','9','.'},{'.','9','8','.','.','.','3','.','.'},{'.','.','.','8','.','3','.','2','.'},{'.','.','.','.','.','.','.','.','6'},{'.','.','.','2','7','5','9','.','.'}};
char[][]b=a.clone();
b[1][1]='Z';
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
clone一維數組
char[]c ={'a','b','c'};
char[]d =c.clone();
d[1]='B';
for(char it:c){
System.out.println(it);
}
實驗結果表明,javaclone二維數組時,clone了一維數組的引用,並非復制了數組中的每一個元素。
吐了