List<Drank> dranken = admin.getBestelling().getDranken();
Iterator<Drank> it = dranken.iterator();
while (it.hasNext()) {
String name = it.next().getName();
String description = it.next().getDescription();
model.addRow(new Object[]{name,description});
}
这是我们的代码。我们想遍历数组。
问题是,如果您使用 it.next()
,它总是转到下一个值,因为我们有 getName()
和 getDescription()
它总是跳过名称或描述,使值彼此不匹配,
有什么建议吗?
最佳答案
使用变量来存储下一个元素。
Drank next = it.next();
String name = next.getName();
String description = next.getDescription();
关于java - 如何从同一个 it.next() 获取多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23131733/