2015-09-07 203 views
0

我有對象定義爲這樣一個數組列表的ArrayList:打印對象

ArrayList<Token> aL = new ArrayList <Token>(); 

當我嘗試打印出此數組列表,我得到了以下的輸出:

[[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]] 

這是我的打印方法:

public void p(ArrayList<Token> t) { 
    System.out.println(tokens); 
} 

於是,我就在數組列表轉換爲字符串:

public void p(ArrayList<Token> t) 
{ 
    String[] s = new String[t.size()]; 
    for (int i=0; i< t.size(); i++) 
    { 
    s[i] = t.get(i).toString(); 
    } 

    System.out.println(s); 
} 

但後來我得到這個作爲輸出:

[Ljava.lang.String;@20dccfab 

我不知道怎麼回事,試圖解決這個問題。任何我可以嘗試的建議?我只想打印出類型令牌的數組列表。

+2

http://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4/29140403 – Reimeus

回答

0

使用toString()方法:

System.out.println(s.toString());