Constructing a String If you are constructing a string with several appends, it may be more efficient to construct it using a StringBuffer and then convert it to an immutable String object. StringBuffer buf = new StringBuffer("Initial Text"); // Modify int index = 1; buf.insert(index, "123"); // I123nitial Text buf.append("456"); // I123nitial Text456 buf.delete(1, 4); // Initial Text456 buf.replace(12, 15, " XY"); // Initial Text XY // Convert to string String s = buf.toString(); // Initial Text XY