views:

76

answers:

1

http://stackoverflow.com/questions/1533662/testing-a-string-is-null

I had this problem(see the link), where I was sure that a String is null, but in fact the String was "null"

jcasso told me:

Since you get the string from a servlet i can say that this is normal.

Java converts a null string to a "null" string on some conditions.

When this situations appear?

+1  A: 

Mostly when you use string concatenation or String.valueOf():

String x = null;
String y = x + ""; // y = "null"
String z = String.valueOf(x); // z = "null"

(There are similar variants, such as using StringBuilder.append((String) null).)

Jon Skeet