java - StringBuffer is obsolete? -


in book "effective java", josh bloch says

stringbuffer largely obsolete , should replaced non-synchronized implementation 'stringbuilder'

.

but in experience, i've still seen widespread use of stringbuffer class. why stringbuffer class obsolete , why should stringbuilder preferred on stringbuffer except increased performance due non-synchronization?

it's obsolete in new code on java 1.5 should use stringbuilder - it's very rare need build strings in thread-safe manner, why pay synchronization cost?

i suspect code see using stringbuffer falls buckets of:

  • written before java 1.5
  • written maintain compatibility older jdks
  • written people don't know stringbuilder
  • autogenerated tools don't know stringbuilder

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -