首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

StringBuffer 与StringBuilder的使用场景

2012-11-10 
StringBuffer 与StringBuilder的应用场景首先翻译JDK规格说明中StringBuffer类描述的一段话:As ofrelease

StringBuffer 与StringBuilder的应用场景
首先翻译JDK规格说明中StringBuffer类描述的一段话:
As of  release JDK 5, this class has been supplemented with an equivalent class designed for use by a single thread, {@link StringBuilder}.  The <tt>StringBuilder</tt> class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization.

自从JDK5发布后,该类(StringBuffer)被补充了一个为在单线程中使用而设计的同等的类StringBuilder。StringBuilder通常要优先于该类被使用,因为它支持所有相同的操作,但速度更快,只是它没有执行任何同步。


结论:
对象A在单线程中使用,则选用StringBuilder A;
对象A被多线程使用,则选用StringBuffer A.
 

热点排行