aspose file tools
The moose likes Java in General and the fly likes StringBuffer VS StringBuilder Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "StringBuffer VS StringBuilder" Watch "StringBuffer VS StringBuilder" New topic
Author

StringBuffer VS StringBuilder

vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
I am a little confused about the difference between StringBuilder and StringBuffer. Practically they both look like they do the same thing and I did Google on this and got this on JGuru :
" The StringBuilder class was introduced with JDK 5.0. Essentially, a StringBuffer is a thread-safe version of StringBuilder. If you are only adding/removing characters from a single-thread, the StringBuilder implementation will be faster. If you are using multiple threads to add and remove characters, use StringBuffer."

I always thought its the other way around. Can someone please tell if the above statement is corret.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
I always thought its the other way around. Can someone please tell if the above statement is corret.
According to the documentation for StringBuffer / StringBuilder, that statement is correct.
[ October 09, 2006: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Originally posted by vishwanath nadimpally:
I am a little confused about the difference between StringBuilder and StringBuffer. Practically they both look like they do the same thing and I did Google on this and got this on JGuru :
" The StringBuilder class was introduced with JDK 5.0. Essentially, a StringBuffer is a thread-safe version of StringBuilder. If you are only adding/removing characters from a single-thread, the StringBuilder implementation will be faster. If you are using multiple threads to add and remove characters, use StringBuffer."

I always thought its the other way around. Can someone please tell if the above statement is corret.


It is, you had it backwards. StringBuffer's methods are synchronized, StringBuilder's aren't. That's the only difference of concern.
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
Originally posted by Ken Blair:


It is, you had it backwards. StringBuffer's methods are synchronized, StringBuilder's aren't. That's the only difference of concern.


thanks guys! I get it now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringBuffer VS StringBuilder
 
Similar Threads
AbstractStringBuilder in jdk1.5
Tracking "free" lines in a dedicated set
String, String Buffer and String Builder
Problem in String Buffer - incrementing char in string
StringBuilder Class