File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -1008,9 +1008,11 @@ public class Student {
1008
1008
1009
1009
#### 2.5 . 1. String StringBuffer 和 StringBuilder 的区别是什么? String 为什么是不可变的?
1010
1010
1011
+ ** 可变性**
1012
+
1011
1013
简单的来说:`String ` 类中使用 final 关键字修饰字符数组来保存字符串,`private final char value[]`,所以`String ` 对象是不可变的。
1012
1014
1013
- > 补充(来自[issue 675 ](https: // github.com/Snailclimb/JavaGuide/issues/675)):在 Java 9 之后,String 类的实现改用 byte 数组存储字符串 `private final byte[] value`;
1015
+ > 补充(来自[issue 675 ](https: // github.com/Snailclimb/JavaGuide/issues/675)):在 Java 9 之后,String 、`StringBuilder` 与 `StringBuffer` 的实现改用 byte 数组存储字符串 `private final byte[] value`
1014
1016
1015
1017
而 `StringBuilder ` 与 `StringBuffer ` 都继承自 `AbstractStringBuilder ` 类,在 `AbstractStringBuilder ` 中也是使用字符数组保存字符串`char[] value` 但是没有用 `final ` 关键字修饰,所以这两种对象都是可变的。
1016
1018
You can’t perform that action at this time.
0 commit comments