public class TestString { public static void main(String[] args) { // TODO Auto-generated method stub String str = new String(); str = "12345"; String str_1 = str; String str_2 = null; str_2 = str; String str_3 = new String(); str_3 = str; System.out.println("str:"+str); System.out.println("str_1:"+str_1); System.out.println("str_2:"+str_2); System.out.println("str_3:"+str_3); str = "2345678"; System.out.println("str:"+str); System.out.println("str_1:"+str_1); System.out.println("str_2:"+str_2); System.out.println("str_3:"+str_3); } }
总结:上述几种方式 String 都是深拷贝
时间: 2024-11-04 22:23:43