大家好,我正在做作业,但我不明白其中的一部分。我已经实现了它,但它没有按预期工作。它说:
Iterate through the ArrayList of Pizza objects calling the toString() method of each object, adding the return value of the method call plus a newline character to the String called list.
这就是我所做的
for(int i=0; i<myList.size()l i++)
{
//myList is arraylist of type Pizza
list +=myList.toString() + "\n";
}
如果有人能说我的实现是否正确,那就太好了。
最佳答案
您需要调用ArrayList#get()方法将返回此列表中指定位置的元素
。
list +=myList.get(i).toString() + "\n";
关于java - 了解数组列表的迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12990701/