Originally posted by Deepak Jain:
If s3 was null. then s3 = s3.toUpperCase(); should have resulted in exception which it did not. After reading Java Specs , it says if one of the operand of "+" is null then null is converted to String "null" and used.
I hope you agree to this.
Thanks
Deepak
String s3 = s1 + s2;
String addition is actually syntatic sugar -- the compiler converts the operations to a StringBuffer/StringBuilder instantiation, followed by calls to the append() method, and finally, by a call to toString() to get the string.
The append() method will convert all null references to "null" strings during the append. So after the addition of two nulls,
you should have s3 equal to "nullnull".
s3 = s3.toUpperCase();
The toUpperCase() method will return a new string, in upper case. So s3 should now be referenced to a string of value "NULLNULL".
Henry