免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3314 | 回复: 3
打印 上一主题 下一主题

StringBuffer 还是 StringBuilder [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-23 23:49 |只看该作者 |倒序浏览
如果线程安全不是你主要关心的,你应该使用StringBuilder替代StringBuffer。

最主要的区别,StringBuffer是线程安全的, 这个类里的所有方法是同步的。这个反过来就会对程序的性能有一定的影响。

StringBuilder 在某些方面和StringBuffer功能类似,但是它不是线程安全的,性能比StringBuffer高。
来自,爪哇杂坛

论坛徽章:
0
2 [报告]
发表于 2007-12-24 16:34 |只看该作者
Thanks for it.

* A mutable sequence of characters.  This class provides an API compatible
* with <code>StringBuffer</code>, but with no guarantee of synchronization.
* This class is designed for use as a drop-in replacement for
* <code>StringBuffer</code> 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
* <code>StringBuffer</code> as it will be faster under most implementations.

论坛徽章:
0
3 [报告]
发表于 2007-12-26 14:50 |只看该作者
我没发现很多需要线程安全的构造字符串的情况。
一般都是在一个方法内部建立一个构造工具,构造字符串。这时哪儿用管什么线程安全?所以只管用StringBuilder就行了。

论坛徽章:
6
CU大牛徽章
日期:2013-04-17 10:59:39CU大牛徽章
日期:2013-04-17 11:01:45CU大牛徽章
日期:2013-04-17 11:02:15CU大牛徽章
日期:2013-04-17 11:02:36CU大牛徽章
日期:2013-04-17 11:02:582015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2007-12-26 20:34 |只看该作者
寒,从来没用过java的StringBuilder
看了一下是since1.5的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP