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; /*/*from w w w . j a v a 2 s.c o m*/ * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ import java.util.Iterator; 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()); } return result; } private static String[] multiply(String[] strings, String placeholder, String[] replacements) { String[] results = new String[replacements.length * strings.length]; int n = 0; for (String replacement : replacements) { for (String string : strings) { results[n++] = replaceOnce(string, placeholder, replacement); } } return results; } public static String replaceOnce(String template, String placeholder, String replacement) { if (template == null) { return null; // returnign null! } int loc = template.indexOf(placeholder); if (loc < 0) { return template; } else { return template.substring(0, loc) + replacement + template.substring(loc + placeholder.length()); } } }