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


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

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

  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

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center