Home >Java >javaTutorial >In java, after assigning the value of String type string s to null, the result obtained after concatenating the string with other strings is the pattern of concatenating the null string with other characters.
String s = null;
s += "hello";
System.out.println(s);
The result is: nullhello
reason:
First apply String.valueOf to get the value of s, and then use StringBuilder to splice hello, so value and hello are spliced;
String s = null;
s = (new StringBuilder(String.valueOf(s))).append("hello").toString();
System.out.println(s);
The above is the detailed content of In java, after assigning the value of String type string s to null, the result obtained after concatenating the string with other strings is the pattern of concatenating the null string with other characters.. For more information, please follow other related articles on the PHP Chinese website!