BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #38791同步于 2015/2/28
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

看了眼StringBuilder和StringBuffer

icyfox
2015/2/28镜像同步7 回复
说说理解: 1、StringBuffer和StringBuilder都是用来操作可变字符串的,内部的实现就是一个char[] 2、StringBuffer是1.0就有的,StringBuilder是1.5才有的 3、它们都继承了AbstractStringBuilder,而AbstractStringBuilder是1.5才有的,所以StringBuffer是1.5的时候重做了? 4、主要是操作都让AbstractStringBuilder包裹了,不同的基本上就是..StringBuilder在super();以后加上了return this; StringBuffer额外加上了synchronized 5、所以就这样的话,StringBuffer是同步的,效率略低,其它没啥区别 @nuanyangyang 是这样的么?Java是这么学的么?
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
nuanyangyang机器人#1 · 2015/2/28
是这样的。也许一开始设计者想把东西都弄成线程安全的,但不现实。 【 在 icyfox 的大作中提到: 】 : 说说理解: : 1、StringBuffer和StringBuilder都是用来操作可变字符串的,内部的实现就是一个char[] : 2、StringBuffer是1.0就有的,StringBuilder是1.5才有的 : ................... 来自「北邮人论坛手机版」
icyfox机器人#2 · 2015/2/28
安全不会影响效率吗? 我不在乎的时候选择不安全的那个就好了吧 【 在 nuanyangyang (暖羊羊) 的大作中提到: 】 : 是这样的。也许一开始设计者想把东西都弄成线程安全的,但不现实。 : 来自「北邮人论坛手机版」
nuanyangyang机器人#3 · 2015/2/28
【 在 icyfox 的大作中提到: 】 : 安全不会影响效率吗? : 我不在乎的时候选择不安全的那个就好了吧 : 会影响效率的。
aiquestion机器人#4 · 2015/3/2
re。。好像HashTable这个古老的类也是线程安全的。。 =。=话说StringBuilder sb = new StringBuilder();写着写着就会笑起来。。。 【 在 nuanyangyang 的大作中提到: 】 : 是这样的。也许一开始设计者想把东西都弄成线程安全的,但不现实。 : 来自「北邮人论坛手机版」
nuanyangyang机器人#5 · 2015/3/2
【 在 aiquestion 的大作中提到: 】 : re。。好像HashTable这个古老的类也是线程安全的。。 : =。=话说StringBuilder sb = new StringBuilder();写着写着就会笑起来。。。 嗯。Java1.0的同步机制简化得太厉害了。 http://docs.oracle.com/javase/7/docs/api/java/util/Hashtable.html As of the Java 2 platform v1.2, this class was retrofitted to implement the Map interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, Hashtable is synchronized. If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable. If a thread-safe highly-concurrent implementation is desired, then it is recommended to use ConcurrentHashMap in place of Hashtable.
shuian0930机器人#6 · 2015/3/5
哈哈哈,这个确实逗 【 在 aiquestion (狼肿粉丝团|学习c++) 的大作中提到: 】 : re。。好像HashTable这个古老的类也是线程安全的。。 : =。=话说StringBuilder sb = new StringBuilder();写着写着就会笑起来。。。 通过『我邮2.0』发布
Enbandari机器人#7 · 2015/3/7
【 在 aiquestion 的大作中提到: 】 : re。。好像HashTable这个古老的类也是线程安全的。。 : =。=话说StringBuilder sb = new StringBuilder();写着写着就会笑起来。。。 常年这么写,哈哈