小编Pra*_*nth的帖子

how to format a string with same value for all placeholders

I have a template string

str = "Hello %s, your name is %s, %s 's born in 1990."
Run Code Online (Sandbox Code Playgroud)

I want to format this string, as below: Hello Mr.P, your name is Mr.P, Mr.P 's born in 1990. I can do the following below:

String.format(str, "Mr.P","Mr.P","Mr.P");
Run Code Online (Sandbox Code Playgroud)

产生以上。还有什么其他方式可以格式化字符串,而不必重复与n参数相同的值次数

java

2
推荐指数
1
解决办法
90
查看次数

标签 统计

java ×1