I\'m sure I\'ve seen String.format used like this before:
String.format(\"Some {1}, {2}, {3}\", var1, var2, var3);
Does this ring
I do not like to specify both index of parameter or its type - mainly when throwing exception and preparing message for it. I like way SLF4j does it. So I wrapped org.slf4j.helpers.MessageFormatter like this:
public static String subst(String string, Object...objects) {
return MessageFormatter.arrayFormat(string, objects).getMessage();
}
Then you can use it like this:
public void main(String[] args) {
throw new RuntimeException(MyUtils.subst("Problem with A={} and B={}!", a, b));
}