What is the Difference Between StringBuffer and StringBuilder in Java ?

StringBuilder was introduced in Java 5. The main difference between both of them is that StringBuffer methods e.g. length(), capacity(), append() are synchronized. But corresponding methods in StringBuilder are not synchronized.

Due to this difference, concatenation of String using StringBuilder is faster than StringBuffer. Now it is considered bad practice to use StringBuffer, because, in most of the scenarios, we perform string concatenation in the same thread.



You May Interest

How Can We Prevent a Deadlock in Java ?

How Will You Implement a Thread Safe JSP Page ?

What are the Rules of Method Overloading and Method Overriding in ...

What is the Difference Between remove Methods of Collection and I ...

What are the Java Collection Classes That Implement List Interfac ...