Here you can find the source of replace(String from, String to, String source)
public static String replace(String from, String to, String source)
//package com.java2s; public class Main { public static String replace(String from, String to, String source) { if (source == null || source.length() == 0 || from == null || from.length() == 0 || to == null) { return source; }//from w w w . j ava2 s . c o m StringBuffer str = new StringBuffer(""); int index = -1; int len = from.length(); while ((index = source.indexOf(from)) != -1) { str.append(source.substring(0, index) + to); source = source.substring(index + len); } str.append(source); return str.toString(); } }