This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Difference between String and StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Difference between String and StringBuffer" Watch "Difference between String and StringBuffer" New topic
Author

Difference between String and StringBuffer

Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47
Hello everybody,
It's amazing to see the help regarding this topic "Difference between String and StringBuffer", Every topic says that String is immutable where as StringBuffer is mutable. But please can any one be more elaborative on this topic. I mean what exactly we can do with StringBufer and we can't with String. A practical explanation will be the best answer to this question. or else a step by step differences. from 1 to say .... will also do.


Thanks in advance
Manoj Amrutkar
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have you looked at the JavaDocs for String and StringBuffer?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ela Jha
Greenhorn

Joined: Jul 17, 2006
Posts: 12
Hey,
that's the difference...... really
when we create a string say
String a="abc";
& then perform the operation
a=a+"xyz";
now "abc" string wud still exist in the pool it won't be modified in addition
there wud be a new string created "abcxyz" and get assigned to a.
so in all there wud be two strings in the pool "abc" & "abcxyz"

but when we use StringBuffer then the original string can be modified instead of second string getting created evrytime.
I hope it wud help.
[ August 23, 2006: Message edited by: Ela Jha ]
Prathap Adusumilli
Greenhorn

Joined: Aug 23, 2006
Posts: 4
Operations on StringBuffer faster than those on String classes.

This link has more info on this...
http://www.javaworld.com/javaworld/jw-03-2000/jw-0324-javaperf.html
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Difference between String and StringBuffer
 
Similar Threads
About String
String, StringBuffer and StringBuilder - Performance
String & StringBuffer -- Difference
string vs stringbuffer
wat diff between stringbuffer & stringwriter