Is there an equivalent to .NET\'s String.Format
in Java?
You can also simply use %s
for string since the index is an optionnal argument.
String name = "Jon";
int age = 26;
String.format("%s is %s years old.", name, age);
It's less noisy.
Note about %s
from the java documentation:
If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().