首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

考考你们解决方法

2012-01-29 
考考你们public static void main(String[] args){final StringBuffer anew StringBuffer(hello)final

考考你们
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);
不能通过编译。

热点排行