Given this method in a class:
21. public String toString() {
22. StringBuffer buffer = new StringBuffer();
23. buffer.append('<');
24. buffer.append(this.name);
25. buffer.append('>');
26. return buffer.toString();
27. }
Which statement is true?
A. This code is NOT thread-safe.
B. The programmer can replace StringBuffer with StringBuilder with no other changes.
C. This code will perform poorly. For better performance, the code should be rewritten:
return "<" + this.name + ">";
D. This code will perform well and converting the code to use StringBuilder will not enhance the
performance.
Answer: B
我认为A是对的,StringBuffer虽是线程安全的,但这段代码却不是线程安全的,如果是在单线程中使用,选B当然是可以的
21. public String toString() {
22. StringBuffer buffer = new StringBuffer();
23. buffer.append('<');
24. buffer.append(this.name);
25. buffer.append('>');
26. return buffer.toString();
27. }
Which statement is true?
A. This code is NOT thread-safe.
B. The programmer can replace StringBuffer with StringBuilder with no other changes.
C. This code will perform poorly. For better performance, the code should be rewritten:
return "<" + this.name + ">";
D. This code will perform well and converting the code to use StringBuilder will not enhance the
performance.
Answer: B
我认为A是对的,StringBuffer虽是线程安全的,但这段代码却不是线程安全的,如果是在单线程中使用,选B当然是可以的
解决方案 »
- \u是什么编码的标示?
- 登录页面可以访问,但是登录时一直是假死状态
- 比较两个java.util.Date类型日期,返回其中的最小值??
- 用java怎么做出类似Dreamweaver那种效果
- 方程信息交流平台(站长交流的好去处)
- 请大家进来看看,有惊喜哦!
- 初学java,请求帮助
- 在SQL中有函数,比如COUNT(*),怎样通过JDBC调用获得函数值????
- if you need i can help you to pass ocp,ccnp,scjp,ciw.....
- 关于javaSwing中图标标签问题
- DataOutputStream的编码问题
- 一个对象只有一个指向自己的引用,它可以被垃圾回收么?
是在toString方法里面定义的本地变量,是线程安全的.
所以A不对