DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Posts
    1

    What do we do with... an empty Vector?

    Code:
    ...
    if (people.isEmpty())
    {
         // What goes here??
    }
    else if (people == null) 
    {
         Vector people = new Vector();
    }
    else
    {
    ...
    Could anyone tell me what should happen in this file if the Vector is empty. The contents of the Vector are required to form a list (in a JList) but I'm not sure what to do with it. I want the JFrame to display regardless of whether the Vector is empty or not. Suggestions?

  2. #2
    Join Date
    Oct 2004
    Posts
    311
    My guess would be that an empty Vector would just display an empty JList

  3. #3
    Join Date
    Feb 2004
    Posts
    541
    You should test for null first. If people==null, then the expression people.isEmpty() will throw a NullPointerException.

  4. #4
    Join Date
    Sep 2004
    Posts
    223
    like mike said, there is really no point to do 2 checks, if you check for null first, then you dont have to worry about the list being empty
    A kram a day keeps the doctor......guessing

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links