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 Vs StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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>
It is sorta covered in the JavaRanch Style Guide.
subject: String Vs StringBuffer