Skip to content

Commit 3bcb61d

Browse files
authored
doc: update java.md (#914)
* method intern can get a ref of the same string in the string pool * doc: update java.md
1 parent ad9aaf7 commit 3bcb61d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

docs/java.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ sb.append("!");
242242
### 比较
243243

244244
```java
245-
String s1 = new String("QuickRef");
245+
String s1 = "QuickRef";
246246
String s2 = new String("QuickRef");
247-
s1 == s2 // false
248-
s1.equals(s2) // true
247+
s1 == s2 // false
248+
s1.equals(s2) // true
249+
// intern 方法获得字符串常量池中的惟一引用
250+
s1 == s2.intern() // true
249251
"AB".equalsIgnoreCase("ab") // true
250252
```
251253

@@ -310,7 +312,7 @@ int[] a3 = new int[]{1, 2, 3};
310312
int[] a4 = new int[3];
311313
a4[0] = 1;
312314
a4[2] = 2;
313-
a4[3] = 3;
315+
a4[3] = 3; // 会出现索引越界异常
314316
```
315317

316318
### 修改 Modify

0 commit comments

Comments
 (0)