My question: Isn't sb initialised to null on Line 1? So, by the end of line 2, isn't content of sb "nullHelloWorld"?
posted 10 years ago
Negative, blue leader!
Remember that automatic (a.k.a. local) variables are not initialized when declared, as member and class variables are. So, though you've declared it, it isn't even null (it's undefined). Furthermore, new StringBuffers start out with an empty buffer, not a buffer of "null". So, new StringBuffer().toString().equals("") would return true.