Checking if variable is null


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Checking if variable is null

  1. #1
    Join Date
    Dec 2002
    Posts
    4

    Unhappy Checking if variable is null

    Hi All

    I have this code

    var1 = request.getParameter("id");

    but sometimes there is no "id" (and thatīs ok), but it returns "null".

    How do I check if var1 is null ?

    if var1 == null donīt work

    thankx
    JoPi

  2. #2
    Join Date
    Mar 2003
    Posts
    84
    use code blocks and actually paste in what you have, I don't know how to help you.
    I'm surprised more of you people don't get hit by cars.

  3. #3
    Join Date
    Mar 2003
    Posts
    32
    What you have to do is use the compareTo function. It will compare the text that is stored in a string to a different value. This is how to check if it has nothing in it:

    if (var1.compareTo("") == 0) {
    //Var1 is null
    }

    Hope this helps, if you have any more questions just post.
    - Master Of Souls
    "Weeks of coding can save hours of planning."


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