Difference Between String Buffer and String Builder

Every method present in the StringBuffer class is synchronized due to this only one thread is allowed to operate on the StringBuffer object at a time. which may create performance problems. To handle this requirement StringBuilder was introduced in Java 1.5v.

Difference Between String Buffer and String Builder

StringBuilder is exactly same as StringBuffer except the following point-

All methods are synchronizedAll methods are non-synchronized
StringBuffer object is thread-safe because only one Thread is allowed to operate on StringBuffer object at a time.StringBuilder object is not Thread safe because multiple Threads are allowed to operate on StringBuilder object at a time.
In StringBuffer performance is relatively low because threads have to wait In StringBuilder performance is relatively high because threads are not required to wait
StringBuffer was introduced in Java 1.0vStringBuilder was introduced in Java 1.5v

Note- Except above difference between StringBuffer and StringBuilder everything is the same including methods and constructors.

Similar Java Tutorials

7 thoughts on “Difference Between String Buffer and String Builder”

Leave a Comment