StringBuffer is certainly better in handling lots of operations than a normal String and can handle the same number of characters as a String. It is also completely thread safe.
However if you are using JDK 5 or later, you might want to think about using a StringBuilder if system performance is your major concern. Only do this though if you can GUARANTEE that only a single thread will be accessing it at any one time (it is not thread safe).
Hope this helps,
darkagn
darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
Why do you need to use a StringBuilder or StringBuffer prior to writing the data to a text file? Is there a reason you can't just use a BufferedWriter?
StringBuilder and StringBuffer are the preferred way to construct long strings from many smaller strings or characters, instead of a large number of concatenations, but if you're writing it to a file, a BufferedWriter should serve the same purpose.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
It's often preferably to collate data before writing it out to disk.
That way you can write larger chunks at once, reducing the number of physical disk operations (which improves performance).
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Yes, good point, I would certainly agree there. The poster didn't give much detail on his process, so it's tough to say what the most efficient arrangement would be.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847