请问 StringBuilder 和 StringBuffer 有什么区别?

badcody 2005-10-14 11:02:42
在append(object)时都是一样在栈中处理吗?
...全文
482 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xijiang007008 2005-12-22
  • 打赏
  • 举报
回复
不同一楼上的看法,虽然StringBuilder和StringBuffer是兼容的,前者非线程安全,后者线程安全。

但是使用时要看情况而定 String 也一样
ChDw 2005-10-21
  • 打赏
  • 举报
回复
从文档上来看,StringBuilder和StringBuffer是兼容的,只是前者非线程安全,后者线程安全。

建议一般使用前者
loveunittesting 2005-10-21
  • 打赏
  • 举报
回复
涨见识了,我最高就用过1。4,后来就没怎么作java了。nnd,不是俺不努力啊,各项技术都变化太快,哪儿学的完啊。
sjjf 2005-10-19
  • 打赏
  • 举报
回复
看源码吧,
手头没有源代码,
以前大致流览过一点,好像 StringBuffer 把有关于空间申请更新等操作的放到StringBuilder

不想装 1.5了
believefym 2005-10-19
  • 打赏
  • 举报
回复
StringBuilder是jdk5.0才有的
loveunittesting 2005-10-19
  • 打赏
  • 举报
回复
StringBuilder?java里有吗?我知道.net里倒是有这个东西,不过没啥区别
believefym 2005-10-19
  • 打赏
  • 举报
回复
楼上的看来是位高手,不过楼主问的是StringBuffer和StringBuilder的区别
jeader 2005-10-19
  • 打赏
  • 举报
回复
String 是不可变长的,修改String对象就等于创建新的String对象。
而 StringBuffer 是可变长的。

我的BLOG有更详细的:http://blog.csdn.net/jeader
believefym 2005-10-14
  • 打赏
  • 举报
回复
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.


可能最大的区别是关于同步的问题,也就是线程安全的问题吧,前者不同步,后者同步,所以前者相对来说效率应该更高一点
badcody 2005-10-14
  • 打赏
  • 举报
回复
谢谢,期待更多的解释....

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧