toString结果

String[] str = new String[] { "a", "b", "c" };
System.out.println(str);
System.out.println(str.toString());

控制台输出结果如下:

[Ljava.lang.String;@1db9742
[Ljava.lang.String;@1db9742

原因如下:

http://blog.csdn.net/java2000_net/article/details/3041577

ArrayList继承AbstractList继承AbstractCollection

AbstractCollection实现Object类的toString方法。

 

    public String toString() {
        Iterator<E> it = iterator();
        if (! it.hasNext())
            return "[]";

        StringBuilder sb = new StringBuilder();
        sb.append('[');
        for (;;) {
            E e = it.next();
            sb.append(e == this ? "(this Collection)" : e);
            if (! it.hasNext())
                return sb.append(']').toString();
            sb.append(',').append(' ');
        }
    }

 

posted @ 2014-11-06 22:08  唾手可得的树  阅读(230)  评论(0编辑  收藏  举报