molinxx
V2EX  ›  问与答

关于 Java 的 2D 输出问题

  •  
  •   molinxx · May 3, 2014 · 3926 views
    This topic created in 4404 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
        1
    Mutoo  
       May 3, 2014   ❤️ 1
    someclass 里面要实现自己的 String toString() 方法。
    davidli
        2
    davidli  
       May 3, 2014   ❤️ 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( )出来
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   874 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 20:39 · PVG 04:39 · LAX 13:39 · JFK 16:39
    ♥ Do have faith in what you're doing.