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");
}
}
ArrayList has an isEmpty()
method that will return true
if the arraylist is empty, false
otherwise. So it looks like you want if(bezoeker.isEmpty())...
The size of an ArrayList can never be negative, so your check for !size()>=0 will never be true. Just check if size()==0.
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