考虑:
System.out.println(new String(new char[10]).replace("\0", "hello"));
Run Code Online (Sandbox Code Playgroud)
有输出:
hellohellohellohellohellohellohellohellohellohello
Run Code Online (Sandbox Code Playgroud)
但:
System.out.println(new String(new char[10]).replace("", "hello"));
Run Code Online (Sandbox Code Playgroud)
有输出:
hello hello hello hello hello hello hello hello hello hello
Run Code Online (Sandbox Code Playgroud)
这些额外空间来自哪里?