内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
String hello = "Hello"; String.format("%s %s %s %s %s %s", hello, hello, hello, hello, hello, hello); hello hello hello hello hello hello
在调用Format方法时,是否需要多次重复hello变量,或者是否有一个简短的版本,允许一次指定参数一次,然后将其应用于所有%s
tokens?
从文档:
%[argument_index$][flags][width][.precision]conversion
可选的argument_index是一个十进制整数,表示参数列表中参数的位置。第一个参数被引用"1$"
,第二个"2$"
等等
String.format("%1$s %1$s %1$s %1$s %1$s %1$s", hello);