String a="123456789";
char temp[]={'1','2','3','4','5','6'};a.getChars(1, 3, temp, 0);
System.out.print(" "+temp.toString());结果应是23456,结果它却是[C@4f1d0d

解决方案 »

  1.   

    这里temp.toString()并不是得到字符串,System.out.print(" " + new String(temp));即可
      

  2.   

    看一下Object类的toString的源码:
    public String toString() {
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }
    再看一下这个:
    import java.util.Arrays;public class Demo1
    {
    public static void main(String[] args)
    {
    String a="123456789";
    char temp[]={'1','2','3','4','5','6'};
    a.getChars(1, 3, temp, 0);

    System.out.println(temp.getClass().getName());
    System.out.println(Integer.toHexString(temp.hashCode()));

    System.out.println(temp.toString());
    System.out.println(Arrays.toString(temp));
    }
    }
      

  3.   

    其实,String跟char[]在JAVA中是不一样的格式……当然可以互相转换。new String(char[] )是一个办法,toString()函数其实是获取一个东东的名字,而不是内容。不过部分数据类型是以自己内容作为名字寄存的,所以大部分时候,要通过toString()获取内容需要在类中覆盖一次。
      

  4.   

    使用.toString()成自然反应了,我也会直接用toString(),看来还是基础知识不够扎实啊。String.valueOf/new String()这下又学到了点东西。