I have a string
String templateString = "The ${animal} jumps over the ${target}.";
valuesMap.put("animal", "quick brown fox");
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);
But there is no entry for attr target in valuesMap. Final resolvedString would be The quick brown fox jumps over the ${target}.
Instead of ${target}, it need to be empty. Values in templatestring which doesn't have key in map should be empty or null.
required The quick brown fox jumps over the.
How to handle this
Your
Map<String,String> valuesMap
contains just the couple key, value"animal", "quick brown fox"
, you have to add the couple"target", ""
to your map like below: