Java: Performance Tip: Use StringBuilder instead of String for a non constant field
Appending to a String is much slower than appending to a StringBuilder.
Append to a StringBuilder
From Logger.entering()
String msg = "Kumar";
for (int i = 0; i < params.length; i++) {
msg = msg + " {" + i + "}";
}
Inside the loop it creates a StringBuilder and another String every time. It can be replaced with code which creates one StringBuilder and String.
StringBuilder msgSB = new StringBuilder("Kumar");
for (int i = 0; i < params.length; i++) {
msgSB.append(" {").append(i).append("}");
}
String msg = msgSB.toString();