StringBuffer methods are synchronized. This *may* make it a good choice
for java environments, although typically they are short-lived objects
that are used on only a single thread. If you only use it on a single
thread, you may as well use StringBuilder which is faster because its
methods are not synchronized. So you should only use StringBuffer if you
want to read/write the contents across multiple threads.

For GWT client code, the general rule is that the synchronized keyword
is ignored because it's single threaded. In the case of StringBuffer and
StringBuilder, they are both emulated and the source code for their
client-side versions is identical apart from the name. So for GWT, it
makes no difference which you use.

StringBuilder was only introduced in Java 1.5, so there's a lot of older
code and examples that use StringBuffer that could/should use
StringBuilder.

Paul

guandalino wrote:
> Hi, GWT provides JRE emulation for both StringBuffer and
> StringBuilder. The Java API says that in single threaded environments
> the preferred choice is to use StringBuilder as it is faster. I also
> remember to have read that browsers way to work is single threaded.
>
> So I'm wondering why and when one should use StringBuffer at all. Can
> you clarify?
>
> Thank you.
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to