TJ- TJ- - 1 year ago 152
Java Question

Java Foreach with a condition

Is it possible for Java foreach to have conditions?

For example,

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

Is there an equivalent to this, such that I can put an AND condition inside

Answer Source


You could use a while loop instead.

Iterator i = list.iterator();
while(i.hasNext() && try) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download