Suggestion: Add the method isEmpty in the classes StringBuilder and StringBuffer

Ulf Zibis Ulf.Zibis at
Tue Feb 12 00:21:12 UTC 2013

Am 11.02.2013 22:26, schrieb Hildeberto Mendonça:
> Hello Ulf,
> On Mon, Feb 11, 2013 at 9:03 PM, Ulf Zibis <Ulf.Zibis at <mailto:Ulf.Zibis at>> wrote:
>     Hi Hildeberto,
>     maybe your believe is correct.
>     You could have a look in the byte code by javap.
>     And additionally you could run a benchmark for both alternatives and compare, if HotSpot
>     compiler would be able to optimize both with same result.
>     I would like to know the result :-)
>     -Ulf
> The issue is fairly documented in the book "Effective Java - Second Edition" by Joshua Bloch, pg. 
> 227: "Item 51: Beware the performance of string concatenation". It gives an example with a "for" 
> saying that "The difference in performance is dramatic." The method with StringBuilder "... is 
> eighty-five times faster than... " the one with String concatenation considering only 100 iterations.

Hi again,

I suspect, "Effective Java" was written some time before javac substituted string concatenation by 
StringBuilder calls, and before HotSpot optimizations were as performant as they are today. I'm 
still inquisitive about some micro-benchmark results.


More information about the core-libs-dev mailing list