Hello I am creating a application that uses arraylists ( practice purposes not real app )
I have created a method that gives me the answer of a math but only if the arraylist contains no object. for some reason I always see the else in my if/else construction.
Here is how I check if the array list contains objects
public void sluitRegistratie() {
aantalBezoekers = bezoeker.size();
if(!(aantalBezoekers >= 0)) {
String str = "Gemiddelde tijd bezoekers: " + (gesommeerdeTijd / aantalBezoekers);
JOptionPane.showMessageDialog(null, str);
}
else {
JOptionPane.showMessageDialog(null, "Bezoekers zijn nog niet weg");
}
}
Basically means that only execute if when aantalBezoekers is NOT greater than zero.
If you want to check if your list is of size zero use something like below:
you could also simply use ArrayList.isEmpty() method to check if an arraylist is empty.