Package cn.com.csuinfo.deepclone;
public class Testclone {
public static void Main (string[] args) {
Int[][] arr1 = {1, 2, 1}, {1, 3, 3, 1}, {1, 4, 6, 4, 1}};
Int[][] ARR2;
Int[][] ARR3 ={{1, 2, 1}, {1, 3, 3, 1}, {1, 4, 6, 41, 1}};
Int[] A = {1, 2, 3, 4};
Int[] A1;
Deepclone DC1 = new Deepclone ();
Deepclone DC2 = new Deepclone ();
Deepclone DC3 = new Deepclone ();
Dc1.setarr (ARR1);
Dc3.setarr (ARR3);
Dc1.seta (a);
try {
ARR2 = Dc1.clone (). Getarr (); Cloning arr1 to ARR2;
A1 = Dc1.clone (). Geta ();
DC2 = Dc1.clone ();
System.out.println ("Before arr1[0][1]:" + arr1[0][1]);
ARR1[0][1] = 20;
System.out.println ("After arr1[0][1]:" + arr1[0][1]);
System.out.println ("After arr12[0][1]:" + arr12[0][1]);
System.out.println ("Before a[1]:" + a[1]);
A1[1] = 22;
System.out.println ("After a[1]:" + a[1]);
/* Printed the source array * *
System.out.println ("arr1:");
For (int[] ar:arr1) {
for (int aa:ar) {
System.out.print (AA + ",");
}
System.out.println ();
}
System.out.println ("ARR2:");
For (int[] AR:DC2.GETARR ()) {
for (int aa:ar) {
System.out.print (AA + ",");
}
System.out.println ();
}
System.out.println ("DC1 equals DC2?")
+ dc1.equals (DC2));
SYSTEM.OUT.PRINTLN ("DC1 ' s hashcode:" + dc1.hashcode ());
System.out.println ("DC2 ' s hashcode:" + dc2.hashcode ());
System.out.println ("DC1:" + dc1.tostring ());
System.out.println ("DC2:" + dc2.tostring ());
/* Make modifications to the cloned array * *
for (int i = 0; i < arr2.length; i++) {
for (int j = 0; J < Arr2[i].length; J + +) {
Dc2.getarr () [i][j] + + 10;
}
}
/* Print the clone and then make the modified array * *
System.out.println ("Modify the arr2 after DC2");
System.out.println ("ARR2:");
For (int[] AR:DC2.GETARR ()) {
for (int aa:ar) {
System.out.print (AA + ",");
}
System.out.println ();
}
System.out.println ("DC1 equals DC2?")
+ dc1.equals (DC2));
SYSTEM.OUT.PRINTLN ("DC1 ' s hashcode:" + dc1.hashcode ());
System.out.println ("DC2 ' s hashcode:" + dc2.hashcode ());
System.out.println ("DC1:" + dc1.tostring ());
System.out.println ("DC2:" + dc2.tostring ());
catch (Clonenotsupportedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
/* Two objects with different arrays to compare * *
System.out.println ("DC1 equals DC3?" + dc1.equals (DC3));
}
}