xxxxxxxxxx
String message = String.format("Hello! My name is %s, I'm %s.", name, age);
xxxxxxxxxx
// String templates have been introduced in JAVA21, they work as follows :
String feelsLike = "hot";
long temperature = 52;
TemperatureUnit unit = TemperatureUnit.CELSIUS;
String message = "Today's weather is \{ feelsLike }, with a temperature of \{ temperature } degrees \{ unit }" ;
xxxxxxxxxx
String template = "status is %s, data key is %s"
String result = String.format(template, status, key);
xxxxxxxxxx
Map<String, String> valuesMap = new HashMap<String, String>();
valuesMap.put("animal", "quick brown fox");
valuesMap.put("target", "lazy dog");
String templateString = "The ${animal} jumped over the ${target}.";
StringSubstitutor sub = new StringSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);