For example I have:
String templateString = "Hi {{customerName}}, you have successfully ordered a {{itemName}}."
Map<String, String> parameters = new HashMap<>();
parameters.put("customerName", "Bob");
parameters.put("itemName", "sofa");
Desired output:
"Hi Bob, you have successfully ordered a sofa."
What would be the best (foolproof, maintainable, time efficient, etc.) way to get the desired output?
I thought of doing something simple:
String output = templateString;
for (Map.Entry<String, String> entry : parameters.entrySet()) {
output = output.replace("{{" + entry.getKey() + "}}", entry.getValue());
}
Is there a better way?