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

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -