日期:2014-05-20  浏览次数:20700 次

考考你们
public static void main(String[] args){
final StringBuffer a=new StringBuffer("hello");
final StringBuffer b=new StringBuffer("world");
a.append(b);
  System.out.println(a);

  final String c = new String("hello");  
  final String d= new String ("world");
c.concat(d);  
  System.out.println(c);  
 
}

------解决方案--------------------
呵呵,这个题目真是会者不难,如果没搞清楚String类的方法,还真拿不准,必须走代码才可以
------解决方案--------------------
不错的tip
楼主有心阿

------解决方案--------------------
http://cache.baidu.com/c?word=string%3B%2E%3Bconcat&url=http%3A//livedocs%2Eadobe%2Ecom/flash/9%2E0%5Fcn/main/00002160%2Ehtml&p=c6769a44d5934eab5bacd3684551cd&user=baidu
1楼 你给解释一下 为什么这里就是 hello world
------解决方案--------------------

------解决方案--------------------
final只是不能改变对象的引用。
------解决方案--------------------
其实很好理解
String是不能更改的

所以当c.concat(d);的时候,c作为一个String是不可能变成concat以后的String的
从而没有变化
------解决方案--------------------
第一个输出:
helloworld
hello
第二个和第三个有错误 :
关键字final表示这个变量只能被赋值一次,一旦被赋值之后,就不能再更改了。
所以我觉得这两句: 
a=a.append(b); 
c=c.concat(d);
不能通过编译。