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

MapreplaceKeyCharacter(Map map, char oldChar, char newChar)
replace Key Character
final Map<String, Object> result = new HashMap<>(map.size());
for (Map.Entry<String, Object> entry : map.entrySet()) {
    final String key = entry.getKey().replace(oldChar, newChar);
    final Object value = entry.getValue();
    result.put(key, value);
return result;
StringreplaceKeyword(String messageTemplate, Map args, String key)
replace Keyword
Object value = args.get(key);
if (value == null)
    value = "";
return messageTemplate.replaceAll("\\$\\{" + regExpescape(key) + "\\}",
        regExpescape(String.valueOf(value)));
StringreplaceMap(String inStr, Map replaceMap)
We substitute string character according to a substitution map.
String str = inStr;
Iterator itr = replaceMap.keySet().iterator();
while (itr.hasNext()) {
    String key = (String) itr.next();
    String value = (String) replaceMap.get(key);
    if (key != null && value != null) {
        str = replaceStr(str, key, value);
return str;
StringreplaceMethodUriWithValues(String methodUri, Map urlParameterKeyValues)
Replace input parameters in the URL with correct values
String uri = methodUri;
for (String key : urlParameterKeyValues.keySet()) {
    uri = uri.replace(new String(key), new String(urlParameterKeyValues.get(key)));
return uri;
MapreplaceNode(Map map, Map replacement, List pathItems)
replace Node
Map<String, Object> m = map;
Map<String, Object> subm = m;
String name = null;
if (pathItems.isEmpty())
    return replacement;
for (String pathItem : pathItems) {
    name = pathItem;
    m = subm;
...
StringreplaceNotContainedWithReplaced(String sentStr, Map mapNotContainedReplaced)
replace Not Contained With Replaced
for (String notContained : mapNotContainedReplaced.keySet()) {
    sentStr = sentStr.replace(notContained, mapNotContainedReplaced.get(notContained));
return sentStr;
StringreplaceOpcodeNames(HashMap replacementValues, final String input)
replace Opcode Names
String retVal = input;
for (Iterator iter = replacementValues.entrySet().iterator(); iter.hasNext();) {
    Map.Entry entry = (Entry) iter.next();
    String key = (String) entry.getKey();
    String value = (String) entry.getValue();
    retVal = retVal.replaceAll("(^|\\s)" + key + "($|\\s)", "$1" + value + "$2");
return retVal;
...
StringreplaceParameters(final String value, final Map paramMap)
replace Parameters
final StringBuilder sb = new StringBuilder();
int paramStart = -1;
char[] chars = value.toCharArray();
for (int i = 0; i < chars.length; i++) {
    switch (chars[i]) {
    case '\\':
        if (paramStart == -1) {
            if (i + 1 < chars.length && (chars[i + 1] == '\\' || chars[i + 1] == '$')) {
...
voidreplaceParameters(Map map, Map originals, Map defaults, Map hards)
Utility method that uppercases the original parameters, adds the default parameters in the map if missing, and replaces the parameters contained in the hards map.
for (String def : defaults.keySet()) {
    String key = def.toUpperCase();
    if (originals.containsKey(key)) {
        map.put(key, originals.get(key));
    } else {
        map.put(def, defaults.get(def));
for (Entry<String, String> e : hards.entrySet()) {
    if (map.containsKey(e.getKey().toLowerCase())) {
        map.put(e.getKey().toLowerCase(), e.getValue());
    } else
        map.put(e.getKey(), e.getValue());
StringreplaceParameters(String query, Map parameters)
replace Parameters
if (parameters != null) {
    for (String parameter : parameters.keySet()) {
        String value = parameters.get(parameter);
        if (value == null)
            value = "";
        query = query.replaceAll("(?i)\\$\\{" + parameter + "\\}", value);
return query;