Yes. From https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax we can see that general formula of placeholders is
%[argument_index$][flags][width][.precision]conversion
We are interested in this part
%[argument_index$][flags][width][.precision]conversion
^^^^^^^^^^^^^^^^^
So you can do it by using adding x$
to your placeholder where x
represents parameter number (indexed from 1) like
String.format("%2$s %1$s", "foo", "bar"); //returns `"bar foo"`
// ^^ ^^ ^^^ ^^^
// | +-----+ |
// | |
// +-----------------+
BTW: if you want to use formatting like {x}
simply use MessageFormat.format
MessageFormat.format("{1} {0}", "foo", "bar")