While working in a Java app, I recently needed to assemble a comma-delimited list of values to pass to another web service without knowing how many elements there would be i
Use an approach based on java.lang.StringBuilder! ("A mutable sequence of characters. ")
Like you mentioned, all those string concatenations are creating Strings all over. StringBuilder
won't do that.
Why StringBuilder
instead of StringBuffer? From the StringBuilder
javadoc:
Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.