我试图借助增强的 for 循环来实现这一点,但我的问题是,如果我在下面的示例中使用迭代器,我如何确保我的返回类型获取“XYZ”的相应值?
List<Apples> a1 = new List<Apples>();
if(a1.iterator().next().equals("XYZ")
{
return a1.iterator().next().getFruits();
}
最佳答案
可能你想实现以下内容
List<Apples> apples = new List<Apples>();
for(Apple a : apples) {
if("xyz".equals(a.getSomethingWhatReturnsString())) return a.getFruits();
}
关于java - 返回列表的迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20939198/