I've a performance related question regarding use of StringBuilder.
In a very long loop I'm manipulating a StringBuilder
and passing it to another method like this:
for (loop condition) {
StringBuilder sb = new StringBuilder();
sb.append("some string");
. . .
sb.append(anotherString);
. . .
passToMethod(sb.toString());
}
Is instantiating StringBuilder
at every loop cycle is a good solution? And is calling a delete instead better, like the following?
StringBuilder sb = new StringBuilder();
for (loop condition) {
sb.delete(0, sb.length);
sb.append("some string");
. . .
sb.append(anotherString);
. . .
passToMethod(sb.toString());
}