1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Update Java内存区域.md

This commit is contained in:
Kou Shuang 2019-11-17 13:46:47 +08:00
parent b1bd3bfb62
commit 3f6eb7bfbe

View File

@ -317,7 +317,7 @@ System.out.println(str2==str3);//false
System.out.println(str3 == str5);//true System.out.println(str3 == str5);//true
System.out.println(str4 == str5);//false System.out.println(str4 == str5);//false
``` ```
![](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019-6/字符串拼接.png) ![字符串拼接](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019-7/字符串拼接-常量池2.png)
尽量避免多个字符串拼接,因为这样会重新创建对象。如果需要改变字符串的话,可以使用 StringBuilder 或者 StringBuffer。 尽量避免多个字符串拼接,因为这样会重新创建对象。如果需要改变字符串的话,可以使用 StringBuilder 或者 StringBuffer。
### 4.2 String s1 = new String("abc");这句话创建了几个字符串对象? ### 4.2 String s1 = new String("abc");这句话创建了几个字符串对象?