Strings, just like any other Object, should be compared using the equals() method.
Using == and != compares references rather than values, and usually does not work.
The following code:
if (variable == "foo") { /* ... */ }
if (variable != "foo") { /* ... */ }