Detect if ArrayList is Null or empty

Posted on 2006-05-19
Medium Priority
Last Modified: 2010-10-05
there is a method wtitten by a co-worker that returns an ArrayList.
I need to know if the ArrayList returns is null or an empty ArrayList.
how would I go about detecting this?

Thanks in advance
Question by:rpong

Accepted Solution

jmadda earned 2000 total points
ID: 16721873
try something like this

ArrayList myAL = yourMethod();

if(myAL==null || myAL.isEmpty()) {
     System.out.println("ArrayList is null or empty");
     //or do whatever you like in here.

Author Comment

ID: 16721911
actually I'm going to check if it's null, if so then I'll create an empty list to plug into a collection.


Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question