I want to execute code if NONE of the items in Arraylist have attribute 'slotted' set to false. I use the following code :
int p=0;
for (int i = 0; i < AppleList.size();i++){
if (AppleList.get(i).slotted = true){
p++;
}
if (p == 0){
//EXECUTE CODE
}
Is there any way to do this better?
You can do it using enhanced-for loop and a label:
label:
{
for(Foo f : AppleList) if(!f.slotted) break label;
// Here you guaranteed that all slotted fields are true
}
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