Why is StringBuilder.toString() returning new String instances for empty strings ?

Jan Ohlsen jan.t.ohlsen at gmail.com
Thu Feb 28 07:47:40 UTC 2013


System.out.println( new StringBuilder().toString() == "" );
-> "false"


Any reason for not returning the "" instance?


    public String toString() {
        return new String(value, 0, count);
    }

-->

    public String toString() {
        return (count > 0) ? new String(value, 0, count) : "";
    }

?



More information about the core-libs-dev mailing list