Here you can find the source of replace(final String source, final List
public static String replace(final String source, final List<String> search, final List<String> repl)
//package com.java2s; /*// w w w. j ava2 s. co m * ? Copyright Foconis AG, 2013 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ import java.util.List; public class Main { public static String replace(final String source, final List<String> search, final List<String> repl) { String result = source; for (int i = 0; i < search.size(); ++i) { if (i < repl.size()) { result = result.replace(search.get(i), repl.get(i)); } else { result = result.replace(search.get(i), repl.get(repl.size() - 1)); } } return result; } public static String replace(final String source, final List<String> search, final String repl) { String result = source; for (String srch : search) { result = result.replace(srch, repl); } return result; } public static void replace(final List<String> source, final List<String> search, final List<String> repl) { for (int i = 0; i < source.size(); ++i) { source.set(i, replace(source.get(i), search, repl)); } } }