The method String format(String format, Object... args) allows insertion of the provided objects into specified locations of a string and formatting them as needed. There are many format specifiers in the class java.util.Formatter. We will demonstrate here only %s, which converts the passed-in object to its String representation by invoking it on the object method toString():
String format = "There is a %s in the %s";
String s = String.format(format, "bear", "woods");
System.out.println(s); //prints: There is a bear in the woods
format = "Class %s is very useful";
s = String.format(format, new A());
System.out.println(s); //prints: Class A is very useful