We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0abe6e1 commit 55cb730Copy full SHA for 55cb730
docs/java/jvm/Java内存区域.md
@@ -354,16 +354,10 @@ String s1 = "计算机";
354
String s2 = s1.intern();
355
String s3 = "计算机";
356
System.out.println(s2);//计算机
357
-System.out.println(s1.equals(s2));//true
358
-System.out.println(s3.equals(s2));//true,因为两个都是常量池中的 String 对象
+System.out.println(s1 == s2);//true
+System.out.println(s3 == s2);//true,因为两个都是常量池中的 String 对象
359
```
360
361
-`s1.equals(s2)` 输出为 true 的原因 :
362
-
363
-1. s1 调用 `intern()` 的时候,因为常量池没有对应的字面量,所以在常量池保存了一个指向 s1 的引用
364
-2. 接下来的 s2 会先去常量池里找,找到对应引用,故指向堆里的 s1
365
-3. 故 `s1.equals(s2)` 为 true
366
367
**字符串拼接:**
368
369
```java
0 commit comments