Java Utililty Methods Map Replace

List of utility methods to do Map Replace

Description

The list of methods to do Map Replace are organized into topic(s).

Method

StringreplaceTemplates(String template, Map entries)
replace Templates
for (Map.Entry<String, String> e : entries.entrySet()) {
    template = template.replaceAll(e.getKey(), e.getValue());
return template;
StringreplaceTokens(String inputString, Map tokenMap)
Replace all tokens in a String.
StringBuilder ret = new StringBuilder(inputString.length() + 10);
Iterator<String> iter = tokenMap.keySet().iterator();
ret.append(inputString);
while (iter.hasNext()) {
    String token = iter.next();
    String value = tokenMap.get(token);
    int found = 0;
    while ((found = ret.indexOf(token, found)) > 0) {
...
StringBuilderreplaceToStringBuilder(String s, String begin, String end, Map values)
replace To String Builder
if ((s == null) || (begin == null) || (end == null) || (values == null) || (values.size() == 0)) {
    return new StringBuilder(s);
StringBuilder sb = new StringBuilder(values.size() * 2 + 1);
int pos = 0;
while (true) {
    int x = s.indexOf(begin, pos);
    int y = s.indexOf(end, x + begin.length());
...
StringreplaceValues(String s, String begin, String end, Map values)
Returns a string with replaced values.
if ((s == null) || (begin == null) || (end == null) || (values == null) || (values.size() == 0)) {
    return s;
StringBuffer sm = new StringBuffer(s.length());
int pos = 0;
while (true) {
    int x = s.indexOf(begin, pos);
    int y = s.indexOf(end, x + begin.length());
...
MapreplaceValuesToSynonyms(Map dic, Map synonims)
replace Values To Synonyms
Map<K, V> ret = new HashMap<K, V>(dic);
for (K key : dic.keySet()) {
    V value = dic.get(key);
    if (synonims.containsKey(value))
        ret.put(key, synonims.get(value));
return ret;
StringreplaceVariable(final String src, final Map value)
replace Variable
int len = src.length();
StringBuffer buf = new StringBuffer(len);
for (int i = 0; i < len; i++) {
    char c = src.charAt(i);
    if (c == '$') {
        i++;
        StringBuffer key = new StringBuffer();
        char temp = src.charAt(i);
...
StringreplaceVariables(String chart, Map variables)
replace Variables
modifyVariables(variables, true);
chart = chart.replaceAll("\\*\\{[\\w\\W]*?\\}\\*", "");
for (String key : variables.keySet()) {
    String val = variables.get(key);
    chart = chart.replaceAll("\\$\\{" + key + "\\}", val);
return chart;
StringreplaceVars(String origString, Map vars)
Performs variable substitution for a string.
StringBuffer finalString = new StringBuffer();
int index = 0;
int i = 0;
String key = null;
String value = null;
while ((index = origString.indexOf("${", i)) > -1) {
    key = origString.substring(index + 2, origString.indexOf("}", index + 3));
    value = (String) vars.get(key);
...
StringreplaceVars(String s, Map m)
Simple utility for replacing variables of the form "{key}" with values in the specified map.
if (s.indexOf('{') == -1)
    return s;
int S1 = 1; 
int S2 = 2; 
int state = S1;
boolean hasInternalVar = false;
int x = 0;
int depth = 0;
...
StringstringReplace(Map map, String line)
string Replace
String tmp = line;
for (Map.Entry<String, String> entry : map.entrySet()) {
    String target = entry.getKey();
    String replacement = entry.getValue();
    tmp = tmp.replace(target, replacement);
return tmp;