The (+) symbol will CONCATENATE any value or null in the given strings.
As your both strings have NULL assigned to it. It'll just return null and append
it with previous string.
Joined: Apr 12, 2006
Manish, Thanks for your reply... Still I am not able to get a clear understanding as why this is happening so.
Aditya, When there is no string existing for the two given variables (a and b), how come null and null are getting concatenated???
ok... though I did not get the complete meaning of the replies... May I know whats the difference between the code snippet that I pasted earlier and the one here below?
String a = "null";
String b = "null";
String c = a+b;
This also prints "nullnull" only as the output.
I strongly believe that there is something to do with the way the string variable/object are allocated the memory.
char data = null;
String a = new String(data);
The above two lines will throw null pointer. That being the case, how is "nullnull" a resulting value???!!!
I am totally lost/confused!
If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time. The result is a reference to a String object (newly created, unless the expression is a compile-time constant expression (§15.28))that is the concatenation of the two operand strings. The characters of the left-hand operand precede the characters of the right-hand operand in the newly created string. If an operand of type String is null, then the string "null" is used instead of that operand.