This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to Check for Null or Empty Value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to Check for Null or Empty Value" Watch "How to Check for Null or Empty Value" New topic
Author

How to Check for Null or Empty Value

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
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

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
Thanks, for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Check for Null or Empty Value
 
Similar Threads
Action form: data getting lost between form submit and setters on ActionForm
Null Compare
Getting 0 rows returned when selecting with null values
String declaration
difficulty in understanding <jsp:forward page=" " />and unusual code execution.