Java:String vs StringBuilder vs StringBuffer

来自WHY42
imported>Soleverlee2016年4月14日 (四) 09:33的版本 (以“有个题目,String,StringBuilder,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 for StringBuffer 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 to StringBuffer as it will be faster under most implementations.