public static void main(String[] args) {
String str = "Hello,World!";
String s1 = "Hello,";
String s2 = "World!";
String s = "Hello," + "World!";
String str2 = s1 + s2;
System.out.println(str2 == str);
System.out.println(s == str);
System.out.println(str2 == s);
System.out.println(s1 == "Hello,");
}
运行结果:
false
true
false
true
有人能解释下,s 与 str2 的内存分配情况吗?