code: protected String replaceString(String str, String fromStr, String toStr) {
          StringBuilder sb = null; // lazy load
          int basePos = 0;
          int nextPos = 0;
          do {
              basePos = str.indexOf(fromStr, nextPos);
              if (nextPos == 0 && basePos < 0) { // first loop and not found
                  return str; // without creating StringBuilder
              }
              if (sb == null) {
                  sb = new StringBuilder();
              }
              if (basePos == 0) {
                  sb.append(toStr);
                  nextPos = fromStr.length();
              } else if (basePos > 0) {
                  sb.append(str.substring(nextPos, basePos));
                  sb.append(toStr);
                  nextPos = basePos + fromStr.length();
              } else { // (basePos < 0) second or after loop only
                  sb.append(str.substring(nextPos));
                  return sb.toString();
              }
          } while (true);
      }
docs: -------