What is the equivalent Java implementation for string.format?
string s = string.Format("{0} - ({1})", myparam1, myparam2);
What is the equivalent Java implementation for string.format?
string s = string.Format("{0} - ({1})", myparam1, myparam2);
String formatted = String.format("%s - (%s)", myparam1, myparam2);
Err... String.format seems like a pretty good candidate. Who would have thought? :-)
There is also MessageFormat.format.
Accepted answer is correct. I would just like to add the Java equivalent of argument index like OP has used in his post. Please, note that I have reversed the argument positions but they would still print in order.
String fmtStr = String.format("%2$s - (%1$s)", myparam2, myparam1);
Format-string argument indices start from 1 in Java.