about AbstractStringBuilder.delete()

George Radev georgeradev at gmail.com
Tue Mar 19 14:41:42 UTC 2019

Dear Team,

Recently I've encountered a time difference between delete() and
setLength() in AbstractStringBuilder when removing elements from the end of
the buffer because of the System.arraycopy call by shift function (~20% if
the buffer is larger).

An example autogenerated code for uddl files:


    public String toString() {

        StringBuilder builder = new StringBuilder("SimpleAttribute [");

        builder.append("name=").append(name).append(", ");

        builder.append("value=").append(value).append(", ");

        // Remove the trailing ", "

*       builder.delete(builder.length() - 2, builder.length()); *

*       //delete() used instead of setLength(builder.length() - 2);*


        return builder.toString();


If there is no reason to favor delete() instead of setLength() in such
border case, and they are equivalent: a very easy correction is possible,
since there is already a check for end >= count in delete(), and adding the
setLength(start) behavior in that case will make the same performance.
Please, consider such change that will make deletion more gnostic,

Thank you for your time,

Best regards,

More information about the core-libs-dev mailing list