Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the reason ?

 
deepak kukreja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
We have two classes namely String and StringBuffer.
If we can do everything with StringBuffer, then what is the
need for String class.
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are for different purposes. A StringBuffer is used when you want to insert/remove/splice/etc characters on the fly, something Strings can't do. A StringBuffer might be loosely thought of as an ArrayList of chars, since it can grow and shrink dynamically. A String can not change its size.
HTH!
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String class is there for speed/performance. It does not carry the same overhead as a StringBuffer object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic