String vs StringBuilder vs StringBuffer in Java

Posted by Editorial Staff | Updated on

In this answer, We have shared about String vs StringBuilder vs StringBuffer in Java. A list of differences between StringBuffer and StringBuilder are given below:

No.StringBufferStringBuilder
1)StringBuffer is synchronized i.e. thread safe. It means two threads can’t call the methods of StringBuffer simultaneously.StringBuilder is non-synchronized i.e. not thread safe. It means two threads can call the methods of StringBuilder simultaneously.
2)StringBuffer is less efficient than StringBuilder.StringBuilder is more efficient than StringBuffer.

String vs StringBuilder vs StringBuffer in Java

Consider below code with three concatenation functions with three different types of parameters, String, StringBuffer and StringBuilder.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers