打印数组列表 [英] Print ArrayList
本文介绍了打印数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含 Address 对象的 ArrayList.
I have an ArrayList that contains Address objects.
我如何打印这个 ArrayList 的值,这意味着我要打印出数组的内容,在这种情况下是数字.
How do I print the values of this ArrayList, meaning I am printing out the contents of the Array, in this case numbers.
我只能用这段代码打印出数组的实际内存地址:
I can only get it to print out the actual memory address of the array with this code:
for(int i = 0; i < houseAddress.size(); i++) {
System.out.print(houseAddress.get(i));
}
推荐答案
list.toString() 已经足够了.
list.toString() is good enough.
接口 List 没有定义 toString() 的契约,但是 AbstractCollection 基类提供了一个有用的实现,ArrayList 继承了这个实现.
The interface List does not define a contract for toString(), but the AbstractCollection base class provides a useful implementation that ArrayList inherits.
这篇关于打印数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文