a StringBuffer/StringBuilder anti-pattern

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

a StringBuffer/StringBuilder anti-pattern

Adam Heath-2
--
StringBuffer sb = new StringBuffer();
sb.append("foo");
while (...) {
     ...
     sb.append("message [" + variable + "] more text [" + another + "]");
}
--

Using '+' when adding to a StringBuffer/StringBuilder allocates more
temporary objects.