doc: update java.md (#914)

* method intern can get a ref of the same string in the string pool

* doc: update java.md
This commit is contained in:
ri-fumo 2025-01-02 11:11:06 +08:00 committed by GitHub
parent ad9aaf759e
commit 3bcb61d409
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -242,10 +242,12 @@ sb.append("!");
### 比较
```java
String s1 = new String("QuickRef");
String s1 = "QuickRef";
String s2 = new String("QuickRef");
s1 == s2 // false
s1.equals(s2) // true
s1 == s2 // false
s1.equals(s2) // true
// intern 方法获得字符串常量池中的惟一引用
s1 == s2.intern() // true
"AB".equalsIgnoreCase("ab") // true
```
@ -310,7 +312,7 @@ int[] a3 = new int[]{1, 2, 3};
int[] a4 = new int[3];
a4[0] = 1;
a4[2] = 2;
a4[3] = 3;
a4[3] = 3; // 会出现索引越界异常
```
### 修改 Modify