Java深層復制與淺層復制對比測試 – JAVA編程語言程序開發技術文章

package se2.Day04;
 
 
 
import java.util.Arrays;
 
 
 
import se.Day03.IOUtils;
 
/** 深層復制與淺層復制對比測試*/
 
public class CopyDemo {
 
public static void main(String[] args) {
 
String[] ary = {"Tom","Jerry"};
 
String[] ary1 = Arrays.copyOf(ary, ary.length);
 
String[] ary2 = (String[]) IOUtils.deepCopy(ary);
 
System.out.println("淺層復制:↓");
 
System.out.println(ary==ary1);
 
System.out.println(ary[0]==ary1[0]);
 
System.out.println("深層復制:↓");
 
System.out.println(ary==ary2);
 
System.out.println(ary[0]==ary2[0]);
 
}
 
}
 

發佈留言