Quote (m0hawk @ Apr 22 2013 08:20am)
For the sake of completeness, you should use StringBuffer (http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.html) when doing operations such as replace, concatenationetc on strings.
1) stringbuilder > stringbuffer in most cases
2) not much point in using sb during concatentation unless loops or similar are involved. the compiler optimizes string literal concatenation. it'll also convert variable concatenation, but not it tends to suck in loops because it'll keep creating new sbs.
3) there isn't really a performance benefit to using replace just once. you still have the original string and the new string as two separate objects either way.
This post was edited by carteblanche on Apr 22 2013 11:28am