StringBuilder VS StringBuffer

I am doing a code review and out of the blue I see that he has replaced the StringBuffer variable with a StringBuilder.

I could ask why but I figured it would be better to read a bit before I ask the question.

The first advantage I find for StringBuilder is that it is faster because it is not synchronized. This means that the advantage of StringBuffer is that it is thread-safe.

After reading this post about never using StringBuffer you can question what thread-safety means with StringBuffer and probably always use StringBuilder.

There is also a bonus performance comment about never using a String in a loop to append values to it.

I have learned a something useful with this code review (as always if I take the time to do it right).

Advertisements

Published by

m5c

Java developper that loves photography and good coffee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s