今天爱分享给大家带来String s = new String(“xyz”)创建了几个字符串对象?【详细介解】,希望能够帮助到大家。
两个对象,一个是静态区的”xyz”,一个是用new创建在堆上的对象。
String str1 = "hello"; //str1指向静态区
String str2 = new String("hello"); //str2指向堆上的对象
String str3 = "hello";
String str4 = new String("hello");
System.out.println(str1.equals(str2)); //true
System.out.println(str2.equals(str4)); //true
System.out.println(str1 == str3); //true
System.out.println(str1 == str2); //false
System.out.println(str2 == str4); //false
System.out.println(str2 == "hello"); //false
str2 = str1;
System.out.println(str2 == "hello"); //true
原文链接:http://blog.itblood.com/2475.html,转载请注明出处。

![新任领主琳迪斯的催眠战记 挂载AI汉化版[新作][1.1G] [催眠SRPG/汉化]](/wp-content/uploads/replace/2025/08/27/fd53c77fb0d7390ebb9d84d374298241.webp)