String (char oldChar, char newChar) { if (oldChar == newChar) return this; int i = count; int x = offset - 1; while (--i >= 0) if (value[++x] == oldChar) break; if (i < 0) return this; char[] newStr = (char[]) value.clone(); newStr[x] = newChar; while (--i >= 0) if (value[++x] == oldChar) newStr[x] = newChar; // Package constructor avoids an array copy. return new String(newStr, offset, count, true); }