带条件的 Java Foreach [英] Java Foreach with a condition
本文介绍了带条件的 Java Foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java foreach 是否可以有条件?
Is it possible for Java foreach to have conditions?
例如
for(Foo foo : foos && try == true)
{
//Do something
}
是否有与此等效的方法,以便我可以在 for
中放入 AND 条件?
Is there an equivalent to this, such that I can put an AND condition inside for
?
推荐答案
没有
您可以改用 while 循环.
You could use a while loop instead.
Iterator iterator = list.iterator();
while(iterator.hasNext()) {
...
}
这篇关于带条件的 Java Foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文