-->

Difference between String, StringBuilder and StringBuffer in Java

Posted by Admin on
String     String Builder String Buffer
Immutable         Mutable              Mutable
Synchronised(thread safe) Non- Synchronised(thread safe) Synchronised(Not thread safe)

=> Use String if you need immutability
=> Use String Buffer if you need mutability and thread safety .
=> Use String Builder if you need  mutability and don't need thread safety.








1 comment:

  1. String is an immutable class while StringBuilder & StringBuffer are mutable classes. StringBuffer is synchronized while StringBuilder is not.

    Below link can be useful to find more differences between String, StringBuffer & StringBuilder

    Difference between String, StringBuffer and StringBuilder

    http://newtechnobuzzz.blogspot.com/2014/07/difference-between-string-stringbuffer.html

    ReplyDelete