How to check if my string is equal to null?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-04-08T17:15:11Z Indexed on 2010/04/08 17:23 UTC
Read the original article Hit count: 169

I want to perform some action ONLY IF my string has a meaningful value. So, I tried this.

if (!myString.eqauls("")) {
doSomething
}

and this

if (!myString.eqauls(null)) {
doSomething
}

and this

if ( (!myString.eqauls("")) && (!myString.eqauls(null))) {
doSomething
}

and this

if ( (!myString.eqauls("")) && (myString!=null)) {
doSomething
}

and this

if ( myString.length()>0) {
doSomething
}

And in all cases my program doSomething in spite on the fact that my string IS EMPTY. It equals to null. So, what is wrong with that?

© Stack Overflow or respective owner

Related posts about java

Related posts about string