Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java - how to check if a string is null

802079Sep 30 2010 — edited Sep 30 2010
//initialize someString
String someString = new String("");

//some code here with that may reset the string someString

//now I need to check if someString is empty
//do I use:
if (someString == null)

//or
Object nullValue = null;
if ((someString.equals(nullValue))

//or
if (someString == "")

//if I need to check if the someString is not empty
//can I use
if(someString != null)



please advise !!!

thx.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 28 2010
Added on Sep 30 2010
21 comments
12,245 views