molinxx
V2EX  ›  问与答

关于 Java 的 2D 输出问题

  •  
  •   molinxx · May 3, 2014 · 4309 views
    This topic created in 4567 days ago, the information mentioned may be changed or developed.
    public String toString(){
    System.out.println(Seats.toString());
    return Arrays.deepToString(Seats);
    }

    输出结果会是someclass@xxxxxxx
    怎么输出table形式的Array?
    2 replies  •  2014-05-03 19:11:30 +08:00
    Mutoo
    Mutoo
    May 3, 2014❤️1
    1
    someclass 里面要实现自己的 String toString() 方法。
    davidli
    davidli
    May 3, 2014❤️1
    2
    引用一段官方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( )出来
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5466 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 02:00 · PVG 10:00 · LAX 18:00 · JFK 21:00
    ♥ Do have faith in what you're doing.