小编Ans*_*nsh的帖子

String replace()在Java中返回额外的空间

考虑:

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)

这些额外空间来自哪里?

java string replace char

17
推荐指数
3
解决办法
712
查看次数

标签 统计

char ×1

java ×1

replace ×1

string ×1