permaculture playing cards*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Buffer & String" Watch "String Buffer & String" New topic
Author

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?

regards,
arun
Dirk Schreckmann
Sheriff

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
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

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

http://www.javaworld.com/javaworld/jw-03-2000/jw-0324-javaperf.html


Co-Author of <a href="http://www.oreilly.com/catalog/jswing2" target="_blank" rel="nofollow">Java Swing</a><br />Co-Creator of <a href="http://www.sun.com/training/catalog/courses/CX-310-055.xml" target="_blank" rel="nofollow">SCJP 5.0</a> and <a href="http://www.sun.com/training/certification/java/associate_beta.xml" target="_blank" rel="nofollow">SCJA</a> exams
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: String Buffer & String
 
Similar Threads
Extract an Email From a String literal
Problems making an unique ID for every word
getValueAt()
Garbage Collection
Question 9, Chapter 6 in K&B