Originally posted by Vijay Kumar Agarwal:
Yes i agree that String is immutable so in such case String can be used when we want to assure that vales doesnt get changed. But we can do the same by putting some restrictions on StringBuffer.
But still can you give me some other reason why String is preferable over StringBuffer?
Thanks
Performance is much better with String.
String is pooled so that if you have the
word or letter or sequence "the" in the pool it will use that String instead of making a new one, like StringBuffer would.
String doesn't have all the bells and whistles that StringBuffer does, which is a feature.