Here you can find the source of substitute(String s, Map
public static String substitute(String s, Map<String, String> map)
//package com.java2s; //License from project: BSD License import java.util.Map; public class Main { private static final String START_FLAG = "${"; private static final String END_FLAG = "}"; public static String substitute(String s, Map<String, String> map) { StringBuilder ret = new StringBuilder(s.length()); int pos = 0; for (int start, end; (start = s.indexOf(START_FLAG, pos)) != -1 && (end = s.indexOf(END_FLAG, start)) != -1;) { ret.append(s.substring(pos, start)).append(map.get(s.substring(start + START_FLAG.length(), end))); pos = end + END_FLAG.length(); }//ww w . j av a 2 s.co m ret.append(s.substring(pos, s.length())); return ret.toString(); } }