Difference between StringBuffer and StringBuilder in java

Previous
Next
In this post, we will see difference between StringBuffer and StringBuilder in java

StringBuffer vs StringBuilder

Parameter
StringBuffer
StringBuilder
Thread-safe
StringBuffer is thread safe. Two threads can not call methods of StringBuffer simultaneously.
StringBuilder is not thread safe, so two threads can call methods of StringBuilder simultaneously.
Performance
It is less performance efficient as it is thread-safe
It is more performance efficient as it is not thread-safe.

Performance comparison between StringBuffer and StringBuilder in single thread environment

When you run above program, you may get below output:

You can go through core java interview questions for more such questions.

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog