Detect if ArrayList is Null or empty

Posted on 2006-05-19
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
    LVL 2

    Accepted Solution

    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

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now