File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes String Buffer & String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Buffer & String" Watch "String Buffer & String" New topic

String Buffer & String

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
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?

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Perhaps you'd have some luck using Cindy's member number as one of the search parameters. It's 3498.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
satish sathineni
Ranch Hand

Joined: May 03, 2004
Posts: 46

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
String str = "Hello";
str = str+"World" ;

StringBuffer sbstr = new StringBuffer("Hello");

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);
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....

Dave Wood
Ranch Hand

Joined: Aug 02, 2004
Posts: 161
More details here...

Co-Author of <a href="" target="_blank" rel="nofollow">Java Swing</a><br />Co-Creator of <a href="" target="_blank" rel="nofollow">SCJP 5.0</a> and <a href="" target="_blank" rel="nofollow">SCJA</a> exams
I agree. Here's the link:
subject: String Buffer & String
It's not a secret anymore!