Difference between StringBuilder and StringBuffer in Java



StringBuilder is non-syncronized and thus is not threadsafe whereas StringBuffer is syncronized and threadsafe. But StringBuffer is slow in comparison to StringBuilder because of synchronization overhead.

StringBuffer should be used in the multithreaded environment whereas if only local variables are in scope or thread synchronization is not needed, StringBuilder is preferred.


Advertisements