Ahmad Ghazi Altarabsheh Ahmad Ghazi Altarabsheh - 1 year ago 144
Java Question

check if arraylist is NOT empty java

I know the isEmpty() method used to check if an arraylist is empty, but I am trying to check if an arraylist is not empty. I tried to look online but I didn't find any useful information on how to do this. My code is like "while ArrayList is not empty then run code).

Answer Source

Invert the result of isEmpty().

public boolean notEmpty(ArrayList a) {
    return !a.isEmpty();
}

That will tell you when a list is not empty.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download