gpt4 book ai didi

java - 了解数组列表的迭代

转载 作者:行者123 更新时间:2023-12-01 06:40:24 26 4
gpt4 key购买 nike

大家好,我正在做作业,但我不明白其中的一部分。我已经实现了它,但它没有按预期工作。它说:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com