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.

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中文网
Release: 2017-06-21 09:02:32
Original
2315 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template