Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10
String is immutable, if you try to alter their values, another object gets created, whereas StringBuffer and StringBuilder are mutable so they can change their values. Thread-Safety  Difference: The difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer. If your string can change, and will be accessed from multiple threads, use a StringBuffer because StringBuffer is synchronous so you have thread-safety.
14th Dec 2017, 5:20 AM
GAWEN STEASY
GAWEN STEASY - avatar