Java Foreach with a condition January 4, 2024 by Tarik No. You could use a while loop instead. Iterator iterator = list.iterator(); while(iterator.hasNext()) { ... }