In Java, as stated in the javadoc:
在Java中,如javadoc中所述:
- The
StringBuffer
class is thread-safe. - The
StringBuilder
class is NOT thread-safe
StringBuffer类是线程安全的。
StringBuilder类不是线程安全的
But is the String
class considered as thread-safe or not ?
但是String类是否被认为是线程安全的?
1 个解决方案
#1
3
According to documentation:
根据文件:
Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared.
字符串是不变的;它们的值在创建后无法更改。字符串缓冲区支持可变字符串。因为String对象是不可变的,所以可以共享它们。
Because Strings are immutable, they are thread safe.
因为字符串是不可变的,所以它们是线程安全的。
#1
3
According to documentation:
根据文件:
Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared.
字符串是不变的;它们的值在创建后无法更改。字符串缓冲区支持可变字符串。因为String对象是不可变的,所以可以共享它们。
Because Strings are immutable, they are thread safe.
因为字符串是不可变的,所以它们是线程安全的。