This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why use StringBuffer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why use StringBuffer?" Watch "Why use StringBuffer?" New topic

Why use StringBuffer?

Roy Tock
Ranch Hand

Joined: Jul 16, 2001
Posts: 83
Java's String class is pretty easy to use. I think it's a well-designed class.
I understand that String concatenation using + actually uses StringBuffer under the hood (so saith the J2SE 1.3 API spec). Other than that, what practical use is there for StringBuffer in real programs?
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I believe that some code like this will be altered by the compiler:

and this is fine, since it's more efficient but happens under the covers so you don't have to worry about it.
If you're building a String in a loop, it can't be done so you have to use a StringBuffer

Roy Tock
Ranch Hand

Joined: Jul 16, 2001
Posts: 83
Yes, thanks!
I agree. Here's the link:
subject: Why use StringBuffer?
Similar Threads
String Buffer
DAN's Qn doubt
A String Buffer question,help!
The difference of String and StringBuffer?
StringTokenizer question