Here you can find the source of replace(Map
public static String replace(Map<String, String> map, String text)
//package com.java2s; //License from project: LGPL import java.util.Map; import java.util.Map.Entry; public class Main { public static String replace(Map<String, String> map, String text) { for (Entry<String, String> entry : map.entrySet()) { text = text.replaceAll(entry.getKey().replaceAll("#", "\\#"), entry.getValue());//from ww w . j ava 2s. co m } return text; } }