Java:String vs StringBuilder vs StringBuffer
有个题目,String,StringBuilder,StringBuffer三者有什么区别?蛋疼了,这又不是我写的,明显可以看文档的东西,考这个有什么鸟用...
JDK的描述如下:
- StringBuffer:
- A thread-safe, mutable sequence of characters.A string buffer is like a {@link String}, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
- StringBuilder
- A mutable sequence of characters. This class provides an API compatible with
StringBuffer
, but with no guarantee of synchronization.This class is designed for use as a drop-in replacement forStringBuffer
in places where the string buffer was being used by a single thread (as is generally the case). Where possible,it is recommended that this class be used in preference toStringBuffer
as it will be faster under most implementations.
- A mutable sequence of characters. This class provides an API compatible with