Skip to content

Instantly share code, notes, and snippets.

@prashantpandey10
Created October 27, 2018 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashantpandey10/532bfa03ca45f99128fe51b28c890908 to your computer and use it in GitHub Desktop.
Save prashantpandey10/532bfa03ca45f99128fe51b28c890908 to your computer and use it in GitHub Desktop.
public class AmpleMarket {
public static void main(String[] args) {
String mainString = "hi {!first name}";
HashMap<String,String> patternDictonary = new HashMap<>();
patternDictonary.put("first name","prashant");
populateTemplate(mainString, patternDictonary);
}
private static void populateTemplate(String mainString, HashMap patternDictonary) {
for (Object key : patternDictonary.keySet()) {
String singleKey = "{!"+key+"}";
if(mainString.contains(singleKey)){
mainString = mainString.replace(singleKey, (CharSequence) patternDictonary.get(key));
}
}
System.out.println(mainString);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment