Thursday, March 28, 2013

Prefer StringBuilder to StringBuffer when thread safety is not a concern

One main difference between StringBuffer and StringBuilder is thread safety. Thread safety is not guaranteed by StringBuilder operations(append, insert ...). This is a main and huge difference between  StringBuilder and StringBuffer.

In my experience I have seen many developers using StringBuffer even when thread safety is not an issue. Using StringBuilder instead will be much faster and effective.