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

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

java - Why is BlockingQueue.take() not releasing the thread? -

jQuery Ajax Render Fragments OR Whole Page -