1. 简介

String是不可变类,且是线程安全的;

StringBuffer是可变类,且是线程安全的;

StringBuilder是可变类,且不是线程安全的。

注:“可变/不可变”指对该类对象进行修改操作时,是否会产生新的对象。对String对象进行修改时会产生新的对象,

对StringBuffer和StringBuilder对象修改时不会产生新的对象。

String类的定义如下,使用了final关键字:

1 /** The value is used for character storage. */
2 private final char value[];
3 
4 /** The offset is the first index of the storage that is used. */
5 private final int offset;
6 
7 /** The count is the number of characters in the String. */
8 private final int count;
View Code

相关文章: