stringbuffer的问题
来源:百度知道 编辑:UC知道 时间:2024/07/01 07:10:01
public class Main {
public static void main(String[] args) {
StringBuffer Source=new StringBuffer("You are the best!");
char[] s=new char[20];
Source.getChars(0,1,s,0);
System.out.println("da an:"+s);
}
}
结果:
run:
da an:[C@35ce36
public static void main(String[] args) {
StringBuffer Source=new StringBuffer("You are the best!");
char[] s=new char[20];
Source.getChars(0,1,s,0);
System.out.println("da an:"+s);
}
}
结果:
run:
da an:[C@35ce36
System.out.println("da an:"+s);中对象s是数组对象,println方法中没有定义数组对象的输出,所以输出的是数组对象s的code,而不是真是的值。
在打印前加上:
String str = new String(s);
System.out.println("da an:"+str);
即可
随便纠正个命名问题,在java中变量名建议使用小写字母开头,Source建议写成source