I\'m sure I\'ve seen String.format
used like this before:
String.format(\"Some {1}, {2}, {3}\", var1, var2, var3);
Does this ring
Yes, that's the typical format string of C#. In Java, you can use the latter, that is, String.format("%s %d %d", ...)
.
An alternative is to use MessageFormat.format("Some {0}, {1}, {2}", var1, var2, var3)
, which uses the .NET curly braces notation, as mentioned by @Tobias, though it requires you to import java.text.MessageFormat. They are also more appropriate for when you are dealing with localized resources, where you typically have external .properties
files with messages in the format Error {0} ocurred due to {1}
.