Please tell me a real time situation to compare
String is immutable, if you try to alter their values, another object gets created, whereas
StringBuilder are mutable so they can change their values.
The difference between
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 is more efficient than
Stringobject is immutable.
StringBuilderis good enough.
StringBufferis synchronous so you have thread-safety.