| 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.
|
 |
 |
|
|
subject: StringBuffer VS StringBuilder
|
|
|