Personalmente me gusta más usar StringBuffer, tal que así:
Código:
static String replace(String original, String replaced, String replacement)
{
StringBuffer theSB = new StringBuffer(original);
int baseIndex = 0;
int badSignIndex = 0;
while ((badSignIndex = original.indexOf(replaced, badSignIndex)) != -1)
{
theSB.delete(badSignIndex + baseIndex, badSignIndex + baseIndex
+ replaced.length());
theSB.insert(badSignIndex + baseIndex, replacement);
baseIndex = baseIndex + replacement.length() - replaced.length();
badSignIndex = badSignIndex + replaced.length();
}
return theSB.toString();
}