Java Foreach with a condition

后端 未结 6 2044
一个人的身影
一个人的身影 2020-12-18 18:27

Is it possible for Java foreach to have conditions?

For example,

for(Foo foo : foos && try == true)
{
//Do something
}

Is t

6条回答
  •  误落风尘
    2020-12-18 19:00

    No.

    You could use a while loop instead.

    Iterator iterator = list.iterator();
    while(iterator.hasNext()) {
        ...
    }
    

提交回复
热议问题