Two Laptop Bag
The moose likes Beginning Java and the fly likes String Vs StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Vs StringBuffer" Watch "String Vs StringBuffer" New topic

String Vs StringBuffer

Reggie McDougal
Ranch Hand

Joined: Sep 27, 2004
Posts: 69
If creating a string with lots of data should I use a stringBuffre instead of the following...

Is there a better way of doing this if sh can some one give me some example code.


You can never drink too much
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Your one line concatenations work fine as a String.

StringBuffer has the edge where you are building up a String out of many pieces, perhaps in a loop.

Mike Gershman
SCJP 1.4, SCWCD in process
Sanjaya Sugiarto
Ranch Hand

Joined: Mar 25, 2004
Posts: 229
And StringBuffer has a big performance benefit too.

<a href="" target="_blank" rel="nofollow">Business Information Technology - Hochschule Furtwangen University, Germany</a>
I agree. Here's the link:
subject: String Vs StringBuffer
It's not a secret anymore!