Here you can find the source of substitute(String str, CharSequence... substitutionSeqs)
public static String substitute(String str, CharSequence... substitutionSeqs)
//package com.java2s; //License from project: Open Source License public class Main { public static final char SUBSTITUTION_PLACEHOLDER_PREFIX_CHAR = '%'; private static final int MIN_SUBSTITUTION_INDEX = 1; public static String substitute(String str, CharSequence... substitutionSeqs) { StringBuilder buffer = new StringBuilder(str.length() + 32); int index = 0; while (index < str.length()) { int startIndex = index; index = str.indexOf(SUBSTITUTION_PLACEHOLDER_PREFIX_CHAR, index); if (index < 0) index = str.length();// ww w. j av a 2 s.c o m if (index > startIndex) buffer.append(str.substring(startIndex, index)); ++index; if ((index < str.length()) && (str.charAt(index) == SUBSTITUTION_PLACEHOLDER_PREFIX_CHAR)) { buffer.append(SUBSTITUTION_PLACEHOLDER_PREFIX_CHAR); ++index; } else { startIndex = index; while (index < str.length()) { char ch = str.charAt(index); if ((ch < '0') || (ch > '9')) break; ++index; } if (index > startIndex) { int substIndex = Integer.parseInt(str.substring(startIndex, index)) - MIN_SUBSTITUTION_INDEX; if ((substIndex >= 0) && (substIndex < substitutionSeqs.length)) { CharSequence substSeq = substitutionSeqs[substIndex]; if (substSeq != null) buffer.append(substSeq); } } } } return buffer.toString(); } }