code: public static 
      String replace(String source, Map<String, String> patternReplacements) {
          if (source == null) {
              return null;
          }
  
          int mapSize = patternReplacements.size();
          String[] patterns = new String[mapSize];
          String[] replacements = new String[mapSize];
  
          Iterator<Map.Entry<String, String>> it = 
              patternReplacements.entrySet().iterator();
          
          for (int i=0; it.hasNext(); i++) {
              Map.Entry<String, String> entry = it.next();
              
              patterns[i] = entry.getKey();
              replacements[i] = entry.getValue();
          }
  
          return replace(source, patterns, replacements);
      }
docs: Applies string replacements using the pattern-replacement pairs provided
  by the given map (associative array). The longest matching pattern is
  used for selecting an appropriate replacement.
  
  @param source the source string
  @param patternReplacements pattern-replacement pairs