What is the main difference between StringBuffer
and StringBuilder
?
Is there any performance issues when deciding on any one of these?
Pretty Good Question
Here are the differences, i have noticed :
StringBuffer :-
StringBuffer is synchronized
StringBuffer is thread-safe
StringBuffer is slow (try to write a sample program and execute it, it will take more time than StringBuilder)
StringBuilder:-
StringBuilder is not synchronized
StringBuilder is not thread-safe
StringBuilder performance is better than StringBuffer.
Common thing :-
Both have same methods with same signatures. Both are mutable.