-2

How do I Return true if the ArrayList is empty, false otherwise?

5
  • 1
    isEmpty Commented Feb 20, 2017 at 4:23
  • Use if (list == null || list.isEmpty()) return false; Commented Feb 20, 2017 at 4:23
  • docs.oracle.com/javase/7/docs/api/java/util/… Commented Feb 20, 2017 at 4:23
  • 1
    @nullpointer I think "7" is a typo... :) Commented Feb 20, 2017 at 5:04
  • @ajb Agreed. Just the first link that came up :) Commented Feb 20, 2017 at 5:11

1 Answer 1

1

There is already a method provided by java.

return list.isEmpty();
Sign up to request clarification or add additional context in comments.

2 Comments

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 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.