Possible Duplicate:
StringBuilder and StringBuffer in Java
what is the difference between StringBuilder and Stringbuffer?
Some methods in StringBuffer are synchronized while StringBuilder is not thread-safe - and faster.
Rule of a thumb - use StringBuilder unless you have a use case, where a StringBuilder is used by more then one Thread (which would be a very rare case).
Taken from the javadoc of StringBuffer:
As of release JDK 5, this class has been supplemented with an equivalent class designed for use by a single thread, {@link StringBuilder}. The StringBuilder class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization.
Basically StringBuffer can be used by multiple threads at the same time, since it's synchronized, but that also makes it a bit slower than StringBuilder which can only be used by one thread at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With