Win a copy of Practical SVG this week in the HTML/CSS/JavaScript 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.
 
You can't expect to wield supreme executive power just because
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!