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

StringreplaceParameters(String str, Map parameters)
Returns a named string, replacing parameters with the values set.
if (str != null && parameters != null) {
    StringBuffer replaceBuffer = new StringBuffer(64);
    for (Map.Entry<String, String> entry : parameters.entrySet()) {
        replaceBuffer.setLength(0);
        replaceBuffer.append("${").append(entry.getKey()).append("}");
        str = substituteSubString(str, replaceBuffer.toString(), entry.getValue());
return str;
StringreplaceParams(String str, Map map)
replace Params
for (String key : map.keySet()) {
    str = str.replaceAll("\\$\\{" + key + "\\}", map.get(key) == null ? "" : map.get(key));
return str;
StringreplacePlaceholders(String script, Map configurations)
replace Placeholders
for (Map.Entry<String, String> configuration : configurations.entrySet()) {
    script = script.replaceAll("\\$\\{" + configuration.getKey() + "\\}", configuration.getValue());
return script;
StringreplacePlaceholders(String string, Map values)
Replaces placeholders of the form ${key} in the supplied string using key / value pairs from the Map provided.
if (string == null || values == null) {
    return string;
StringBuffer buffer = new StringBuffer(string);
int start = buffer.indexOf(PLACEHOLDER_PREFIX);
int end = buffer.indexOf(PLACEHOLDER_SUFFIX);
while (start != -1 && end != -1) {
    String placeholder = buffer.substring(start + PLACEHOLDER_PREFIX.length(), end);
...
StringreplaceProperties(final CharSequence string, final Map properties)
replace Properties
if (string == null) {
    return null;
} else {
    final StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < string.length(); ++i) {
        char c = string.charAt(i);
        switch (c) {
        case '$':
...
StringreplaceQueryParameterInUrl(String fullUrl, Map newParameter)
Replaces query parameters found in a URL string with specified parameters.
Map<String, String> parameter = urlToQueryParameterMap(fullUrl);
parameter.putAll(newParameter);
String url = splitUrlParameter(fullUrl)[0];
return addQueryParameterToUrl(url, parameter);
StringreplaceSeparator(String value, String separator, Map map)
replace Separator
if (map == null || map.size() == 0) {
    return value;
StringBuilder sb = new StringBuilder();
String[] valueSplit = value.split(separator);
for (int i = 0; i < valueSplit.length; i++) {
    String replace = map.get(valueSplit[i]);
    if (null != replace && !"".equals(replace)) {
...
StringreplaceString(Map bodyToReplace, String replacingContent)
replace String
for (Map.Entry<String, Object> entrySet : bodyToReplace.entrySet()) {
    System.out.println(entrySet.getKey() + "\n\n String to replace\n\n" + entrySet.getValue());
    replacingContent = replacingContent.replace(entrySet.getKey(), String.valueOf(entrySet.getValue()));
return replacingContent;
StringreplaceString(String source, Map args)
Replace string
int startIndex = 0;
int openIndex = source.indexOf('{', startIndex);
if (openIndex == -1) {
    return source;
int closeIndex = source.indexOf('}', startIndex);
if ((closeIndex == -1) || (openIndex > closeIndex)) {
    return source;
...
StringreplaceString(String uri, String baseURI, Map prefixes)
=====================================================================================
Shorten an URI by removing all bases or using its prefixes
if (baseURI != null && uri.startsWith(baseURI)) {
    return uri.replace(baseURI, "");
} else {
    if (prefixes != null) {
        for (Entry<String, String> prefix : prefixes.entrySet())
            uri = uri.replace(prefix.getValue(), prefix.getKey());
    return uri;
...