The reason it's not safe to use it in a VM before 1.5 is because StringBuilder
just didn't exist before 1.5. If you look at the JavaDoc for StringBuilder
you can see it has only exited since 1.5.
Regarding when to use it in 1.5+, you are mostly safe in just substituting StringBuffer
out in favor of StringBuilder
. The case when you wouldn't want to do this is if you have more than one thread writing to the buffer. However, in most cases when you just want to make a String
and return it, from a toString()
method, for instance, you should be safe.