How do I Return true if the ArrayList is empty, false otherwise?
1 Answer
There is already a method provided by java.
return list.isEmpty();
2 Comments
user7590997
Thank you! I am very new to coding and don't know what is already provided or not. Is there a way to check?
ajb
@user7590997 By looking in the javadoc. You can find the
ArrayList class and click on it to see the methods it provides. But note that ArrayList inherits methods from other classes, so be sure to scroll down to see all the methods. Keep this site bookmarked. Even many of us who have years of experience in Java refer to the javadoc a lot.
if (list == null || list.isEmpty()) return false;