Why String class is immutable and StringBuffer is mutable?

Why String class is immutable and StringBuffer is mutable?
[65 byte] By [atmaram.pradhana] at [2007-11-27 8:22:17]
# 1
Because.Please search the forums. These questions have been asked and answered literally thousands of times previously.
cotton.ma at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 2

Well, if they were both mutable or both immutable, why would we need two classes?

Immutability is a good thing for value holders (like String, Integer, etc.--Date should be immutable too, IMHO). It means you don't have to copy the thing for fear of someone else modifying it, keeps code simpler and lets it more directly express your intent.

Mutablity is a good thing for when you need to build up a value to put into an immutable value holder, or for when things do legitimately need to change and you don't want to have to create whole new object.

Why do both screws and nails exist?

jverda at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 3
Duke ****.
cotton.ma at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 4
> Duke ****.Sheeit. You jus jealous cuz Pimp Daddy Yizzawmizzark wouldn't take yo skankass inta his stable, yo.
jverda at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 5
was that English?
sachin.agrawala at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 6
It's just about as good English as usually seen around here, except from some of us old fuddy-duddies ...
ejpa at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 7
Actually i have never heard anything like before so i do not understand it and want to understand it.
sachin.agrawala at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 8
> Actually i have never heard anything like before so i> do not understand it and want to understand it.Trust me, you don't want to understand it. There is, IMO, a distinct nobility in being ignorant of hip-hop slang
georgemca at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...
# 9
i got that!
sachin.agrawala at 2007-7-12 20:10:56 > top of Java-index,Core,Core APIs...