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

What is Volatile Keyword in Java ?

Why Did Oracle Release a New Version of Java Like Java 8 ?

Why Do We Use Tag Library in JSP ?

What is the Difference Between pass by reference and pass by valu ...

What is the Importance of hashCode and equals Methods in Java ?