I iterate through a Set. If a value of a CarDetail is not set i want that the loop starts again with the next CarDetail. But somehow my continue wont work. Isnt it possible to use a continue with an iterator?
final Set<CarDetail> tmpDetail = new HashSet<CarDetail>(details);
for(Iterator<CarDetail> iter = tmpDetail.iterator(); iter.hasNext();){
CarDetail detail = iter.next();
if(detail.getBack() == null){
continue;
}
... do something
}
There is nothing wrong with using continue with iterators. You can even use this with an enhanced for loop (for each loop):
final Set<CarDetail> tmpDetail = new HashSet<CarDetail>(details);
for(CarDetail detail : tmpDetail) {
if(detail.getBack() == null) {
System.out.println("Skipping over " + detail.toString() );
continue;
}
System.out.println("Processing car detail: " + detail.toString() );
//... do something
}
How are you sure that the continue statement is being ignored in the code you posted? With a few little println statements, we can verify that the continue is working as we expect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With