Correct format string for String.format or similar

后端 未结 4 855
梦如初夏
梦如初夏 2021-02-05 01:21

I\'m sure I\'ve seen String.format used like this before:

String.format(\"Some {1}, {2}, {3}\", var1, var2, var3);

Does this ring

4条回答
  •  礼貌的吻别
    2021-02-05 01:45

    What you are looking for is MessageFormat, which uses a given format and input parameters, e.g.

    MessageFormat.format("Some {0}, {1}, {2}", var1, var2, var3);
    

    And as already mentioned, String.format can still do the job using the alternate syntax, but it is less powerful in functionality and not what you requested.

提交回复
热议问题