Skip to content

Instantly share code, notes, and snippets.

@xdu
Created August 25, 2011 08:28
Show Gist options
  • Save xdu/1170229 to your computer and use it in GitHub Desktop.
Save xdu/1170229 to your computer and use it in GitHub Desktop.
java string variable replacement
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment