V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
molinxx
V2EX  ›  问与答

关于 Java 的 2D 输出问题

  •  
  •   molinxx · 2014-05-03 10:19:29 +08:00 · 3176 次点击
    这是一个创建于 3639 天前的主题,其中的信息可能已经有所发展或是发生改变。
    public String toString(){
    System.out.println(Seats.toString());
    return Arrays.deepToString(Seats);
    }

    输出结果会是someclass@xxxxxxx
    怎么输出table形式的Array?
    2 条回复    2014-05-03 19:11:30 +08:00
    Mutoo
        1
    Mutoo  
       2014-05-03 10:44:58 +08:00   ❤️ 1
    someclass 里面要实现自己的 String toString() 方法。
    davidli
        2
    davidli  
       2014-05-03 19:11:30 +08:00   ❤️ 1
    引用一段官方API里的内容
    public static String deepToString(Object[] a)

    Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.

    这个deepToString( ) 只是保证array中的array也被toString( ).
    一个object默认的toString( )好像是
    return getClass().getName() + "@" + Integer.toHexString(hashCode());
    所以要自己overload一个toString( )出来
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3455 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.