No need to change anything, compact and easy to read, javac will use StringBuilder to actually concatenate, if you decompile your Temp.class, you will see
public String toString() { return (new StringBuilder("Temp [tempName=")).append(tempName).append(", tempValue=").append(tempValue).append("]").toString(); }
But in other situations, such as
String[] a = { "1", "2", "3" }; String str = ""; for (String s : a) { str += s; }
+ or += - a real performance killer, see decompiled code
String str = ""; for(int i = 0; i < j; i++) { String s = args1[i]; str = (new StringBuilder(String.valueOf(str))).append(s).toString(); }
at each iteration, a new StringBuilder is created and then converted to String. Here you should use StringBuilder explicitly
StringBuilder sb = new StringBuilder(); for (String s : a) { sb.append(s); } String str = sb.toString();
source share