Explain the difference between StringBuilder and StringBuffer class. StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer. What is the difference between StringBuffer and String class? String class objects are immutable. They can not be changed and read only.
The StringBuffer class objects are mutable. They can be changed.
The difference between these two classes is StringBuffer is faster than String at the time of concatenating strings. To concatenate a string to another string object, '+' sign is used. In this process, an intermediately string object is created and to be stored in one string object whereas using StringBuffer, it just joins / concatenates the new string to the existing string.
|