Here you can find the source of multiply(String string, Iterator placeholders, Iterator replacements)
public static String[] multiply(String string, Iterator placeholders, Iterator replacements)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static String[] multiply(String string, Iterator placeholders, Iterator replacements) { String[] result = new String[] { string }; while (placeholders.hasNext()) { result = multiply(result, (String) placeholders.next(), (String[]) replacements.next()); }//from w w w. j av a2 s . co m return result; } private static String[] multiply(String[] strings, String placeholder, String[] replacements) { String[] results = new String[replacements.length * strings.length]; int n = 0; for (int i = 0; i < replacements.length; i++) { for (int j = 0; j < strings.length; j++) { results[n++] = replaceOnce(strings[j], placeholder, replacements[i]); } } return results; } public static String replaceOnce(String template, String placeholder, String replacement) { if (template == null) { return template; // returnign null! } int loc = template.indexOf(placeholder); if (loc < 0) { return template; } else { return new StringBuilder(template.substring(0, loc)).append(replacement) .append(template.substring(loc + placeholder.length())).toString(); } } public static String toString(Object[] array) { int len = array.length; if (len == 0) return ""; StringBuilder buf = new StringBuilder(len * 12); for (int i = 0; i < len - 1; i++) { buf.append(array[i]).append(", "); } return buf.append(array[len - 1]).toString(); } }