Difference between StringBuilder and StringBuffer

后端 未结 30 2227
独厮守ぢ
独厮守ぢ 2020-11-21 15:06

What is the main difference between StringBuffer and StringBuilder? Is there any performance issues when deciding on any one of these?

30条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 15:52

    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.

提交回复
热议问题