I have the following code
System.out.println("" + null);
and the output is null.
How does Java do the trick in string concatenation?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because Java converts the expression
"A String" + xto something along the lines of"A String" + String.valueOf(x)In actual fact I think it probably uses
StringBuilders, so that:resolves to the more efficient
This uses the
appendmethods on String builder (for each type), which handlenullproperly