How do I Return true if the ArrayList is empty, false otherwise?
Asked
Active
Viewed 309 times
-2
-
1[isEmpty](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#isEmpty()) – Scary Wombat Feb 20 '17 at 04:23
-
Use `if (list == null || list.isEmpty()) return false;` – Tim Biegeleisen Feb 20 '17 at 04:23
-
https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#isEmpty() – Naman Feb 20 '17 at 04:23
-
1@nullpointer I think "7" is a typo... :) – ajb Feb 20 '17 at 05:04
-
@ajb Agreed. Just the first link that came up :) – Naman Feb 20 '17 at 05:11
1 Answers
1
There is already a method provided by java.
return list.isEmpty();

Deepak M
- 223
- 4
- 14
-
Thank you! I am very new to coding and don't know what is already provided or not. Is there a way to check? – user7590997 Feb 20 '17 at 04:29
-
@user7590997 By looking in the [javadoc](https://docs.oracle.com/javase/8/docs/api/). 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. – ajb Feb 20 '17 at 05:02