StringBuffer vs. List
July 25th, 2008 | by sean |Just a quick tip that Shayne pointed out to me (after I had spent a few minutes staring at my code), use StringBuffer if you ever need to have a modifiable string.
Coldfusion uses the Java String class rather than StringBuffer. This means that everytime you modify a string, ColdFusion creates a copy of it in the background and doesn’t de-allocate the old one. Obviously this can quickly eat through your server’s memory. If you plan on only doing a few string modifications (or never modifying it), go ahead and use ColdFusion’s built in string class. Otherwise it will be better to use a StringBuffer. If you ever want to use a StringBuffer object as a normal ColdFusion string, just use the StringBuffer’s toString() method.
Another benefit to StringBuffer is the number of functions available to you for things like substrings and treating the string as an array. For a good example of replacing a ColdFusion string with a StringBuffer see this post.
Tags: cfsucks, cfwtf, gotchas, java, list, parsing, stringbuffer