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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值