Samsung Interview Question
Software Engineer / DevelopersString is an immutable class while StringBuilder & StringBuffer are mutable classes. StringBuffer is synchronized while StringBuilder is not.
Below link can be useful to find more differences between String, StringBuffer & StringBuilder
<a href="newtechnobuzzz.blogspot.com/2014/07/difference-between-string-stringbuffer.html">Difference between String, StringBuffer and StringBuilder</a>
newtechnobuzzz.blogspot.com/2014/07/difference-between-string-stringbuffer.html
StringBuffer: methods are synchronized, available since 1.0.
- Anonymous June 22, 2010StringBuilder: methods are not synchronized, available since 1.5.
So, use StringBuffer for compatibility with old versions of Java or if implicit synchronization is desired (bad style IMHO) and StringBuilder otherwise.
(This is really quite a bad interview question.)