Java Map Replace replaceCharacters(String sequence, Map map, boolean reverse)

Here you can find the source of replaceCharacters(String sequence, Map map, boolean reverse)

Description

replace Characters

License

Open Source License

Declaration

private static String replaceCharacters(String sequence, Map<String, String> map, boolean reverse) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    private static String replaceCharacters(String sequence, Map<String, String> map, boolean reverse) {

        if (reverse) {

            for (Entry<String, String> entry : map.entrySet()) {

                sequence = sequence.replace(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
            }//w  w  w . j av a 2s  .c o m

        } else {

            for (Entry<String, String> entry : map.entrySet()) {

                sequence = sequence.replace(String.valueOf(entry.getValue()), String.valueOf(entry.getKey()));
            }
        }

        return sequence;
    }
}

Related

  1. replaceAll(String template, Map variables)
  2. replaceAllOccurrences(String str, Map replacementMap)
  3. replaceAllRegex(String input, Map replacements)
  4. replaceByMap(String _searchStr, Map _replacements)
  5. replaceByMap(String tpl, Map map)
  6. replaceCharactersInArray(char[] characters, Map replacements)
  7. replaceElements(Map destinationMap, Map sourceMap)
  8. replaceEntities(final Map replacements, final String xml)
  9. replaceFromMap(final String string, final Map replacements)