File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding StringBuffers and StringBuilders Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding StringBuffers and StringBuilders" Watch "Regarding StringBuffers and StringBuilders" New topic

Regarding StringBuffers and StringBuilders

praveen raaj

Joined: Nov 30, 2009
Posts: 11
Hi Friends,
can you explain to me what is the common use for StringBuffers and StringBuilders?
Patel Chintan
Ranch Hand

Joined: Mar 01, 2007
Posts: 80

The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. 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.

Chintan Patel, SCJP1.5,
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
StringBuffer and StringBuilder classes are both used to create mutable string objects which is not possible with String class the only difference between the two is already stated by chintan.

SCJP 1.6 96%
Afzal Rehman
Ranch Hand

Joined: Dec 16, 2009
Posts: 39
StringBuffer is syncronized
StringBuilder is unsyncronized.
StringBuffer and StringBuilder are mutable.
StringBuilder was added in java 5 API it's same as StringBuffer except is not thread safe
StringBuilder is faster then StringBuffer as performance point of view.

SCJP 6.0
Phungsuk Wangdu
Ranch Hand

Joined: Nov 04, 2009
Posts: 114
well common use could be if we want mutable string objects
and both are used as an alternative to stiring
I agree. Here's the link:
subject: Regarding StringBuffers and StringBuilders
It's not a secret anymore!