2015-09-07 131 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());