[英]Trying to add elements to a list when looping into another list java
I have a code with 2 lists: 我有2个列表的代码:
final List<String> imageList = new ArrayList<String>();
and 和
List<BacktoryObject> todoNotes = response.body();
for (BacktoryObject todo : todoNotes) {
}
I just want to loop into todoNotes and add elements to imageList for example like: 我只想循环到todoNotes并向imageList添加元素,例如:
List<BacktoryObject> todoNotes = response.body();
for (BacktoryObject todo : todoNotes) {
imageList.add("hello");
}
but it didn't work and nothing added to imageList
and I'm 100% sure my for loop works perfectly. 但是它不起作用,并且没有向imageList
添加任何内容,而且我100%确信我的for循环可以正常工作。 What should I do for this? 我该怎么办?
By the looks of it, your code should work fine. 从外观上看,您的代码应该可以正常工作。 You can try this though. 您可以尝试一下。 It does the same thing, but much faster. 它做同样的事情,但是速度更快。
int n = todoNotes.size();
while (n-- > 0) imageList.add("hello");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.