• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Check for Null or Empty Value  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1760
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the following code section I to try and check for an empty or null value but it never is empty even though the string I send to it is blank.

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check for null using if(myRef == null) or if (myRef != null).

However, a "blank" or empty String ("") is not null. It's a String with a length of zero. You can check this using myString.length(), after you verify that the reference is not null.

[ August 30, 2007: Message edited by: marc weber ]
 
Steve Dyke
Ranch Hand
Posts: 1760
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, for the help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!