String contains a bunch of useful methods such as String.replace(CharSequence, CharSequence) that are completely missing from StringBuilder. Is there a reason why?
Is there an easy way to implement these methods without the huge overhead of invoking StringBuilder.toString() which copies the string every time?
Since
StringBuilderprovides bothindexOf(String,int)andreplace(int,int,String)one can easily reproduce the functionality. The only drawback here is that the arguments can’t be anyCharSequenceobjects, but must beStrings instead.When handling huge string-like objects and doing lots of replace operations, then a specialized API like Ropes for Java could be used.