Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Buffer & String

 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

I could remember there was some write up by Cindy on the above two.. could not able to locate on the site. Can somebody help me?

regards,
arun
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you'd have some luck using Cindy's member number as one of the search parameters. It's 3498.
 
satish sathineni
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Object type Comparision

String -->> immutable (Value once assigned cannot be modified)
StringBuffer -->> mutable (Value can be modified).

Performance comparision

Performance wise StringBuffer is better when u compare String with StringBuffer in string manipulation that is
ex:
String str = "Hello";
str = str+"World" ;
sop(str);

StringBuffer sbstr = new StringBuffer("Hello");
sbstr.append("world");
sop(sbstr.toString());

if we look at the above example the major and hidden difference is internally how JVM handles the string manipulation....

when we say str = str+"World";

internally ::

StringBuffer xxx = new StringBuffer(str);
xxx.append("World");
str = xxx.toString();

Now u can make out that internally there is a overhead of converting the String str to StringBuffer and applying append method on that and finally it is assigned backto the str the modifed str....


Cheers
satish
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More details here...

http://www.javaworld.com/javaworld/jw-03-2000/jw-0324-javaperf.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic