Is there a faster method then StringBuilder for a max 9-10 step string concatenation?
- by Pentium10
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?