rodpuc
Janeiro 29, 2009, 1:11pm
#1
StringBuffer X StringWriter
Quais as diferenças/vantagens de cada?
Cara. StringWriter eu não conheço. Conheço o StringBuilder, e a diferença dele pro StringBuffer é que não é sincronizado…
ja vi questão semelhante, só que envolvendo StringBuffer vs StringBuilder.
nesse caso, parece que StringBuffer é thread safe enqto StringBuilder não é…
agora esse StringWriter ainda nao tinha usado…
mas uma rápida “googlada” retornou isso:
StringBuffer vs StringBuilder vs StringWriter
All are mutable objects which can be used to concat Strings (which are immutable) more efficiently then using the overloaded ?+? operator.
StringBuffer is synchronised (so it can be safely accessed by multiple threads)
However, it is less performant than StringBuilder (whose methods aren?t sync?d and can only safely be used where access is only by a single thread).
Both Builder and Buffer are mutable and can be manipulated (append, delete, insert etc.)
StringWriter implements the Writer interface (which used to write to streams, so no deletes/inserts just appends).
StringWriter also uses a StringBuffer underneath in its impl so should be threadsafe (but again not as performant as Builder).
In most cases, you would use Builder.
uma pesquisada antes de postar geralmente trás resultados mais rápidos… :-p
[]s