Is there a faster method then StringBuilder for a max 9-10 step string concatenation?
Posted
by Pentium10
on Stack Overflow
See other posts from Stack Overflow
or by Pentium10
Published on 2010-05-25T20:32:24Z
Indexed on
2010/05/25
20:51 UTC
Read the original article
Hit count: 228
I have this code to concate some array elements:
StringBuilder sb = new StringBuilder();
private RatedMessage joinMessage(int step, boolean isresult) {
sb.delete(0, sb.length());
for (int i = 0; i <= step; i++) {
if (mStack[i] == null)
continue;
rm = mStack[i].getCurrentMsg();
if (rm == null || rm.msg.length() == 0)
continue;
if (sb.length() != 0) {
sb.append(", ");
}
sb.append(rm.msg);
}
return sb.toString();
}
Important the array holds max 10 items, so it's not quite much.
My trace output tells me this method is called 18864 times, 16% of the runtime was spent in this method. Can I optimize more?
© Stack Overflow or respective owner