java数组的clone方法
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了一维数组的引用,并非复制了数组中的每一个元素。
吐了
如需转载,请注明出处
如有侵权,联系删除
2290713181@qq.com
如有侵权,联系删除
2290713181@qq.com