Use org.apache.commons.lang3.text.StrSubstitutor
Example 1 (the simplest example is to use this class to replace Java System properties):
StrSubstitutor.replaceSystemProperties(
"You are running with java.version = ${java.version} and os.name = ${os.name}.");
Example 2:
Map valuesMap = HashMap();
valuesMap.put("animal", "quick brown fox");
valuesMap.put("target", "lazy dog");
String templateString = "The ${animal} jumped over the ${target}.";
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);
getting:
The quick brown fox jumped over the lazy dog.
source
share