Home  >  Article  >  Java  >  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.

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.

PHP中文网
PHP中文网Original
2017-06-21 09:02:322243browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn