public class Test{
public static void main(String[] args) {
char test[]={'w','e','r'};
String str=new String(test);
String trs=test.toString();
System.out.println("str="+str);//str=wer
System.out.println("trs="+trs);//trs=[C@35ce36
}
}这两个为什么不一样?3Q
public static void main(String[] args) {
char test[]={'w','e','r'};
String str=new String(test);
String trs=test.toString();
System.out.println("str="+str);//str=wer
System.out.println("trs="+trs);//trs=[C@35ce36
}
}这两个为什么不一样?3Q
getClass().getName() + '@' + Integer.toHexString(hashCode())
每一个对象都有toString方法,默认情况下,toString方法的返回值是该对象的哈希码,除非某些特别的类把toString方法重载了,才可能返回一些有意义的东西。很显然,数组对象的toString方法没有被重载,因此它返回的是该对象的哈希码,也就是[C@35ce36
Allocates a new String so that it represents the sequence of characters currently contained in the character array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the newly created string. toString
public String toString()Returns a string representation of the object.