Given the 2 toString()
implementations below, which one is preferred: 給定如下2個toString()
實現,首選其中一種: app
public String toString(){ return "{a:"+ a + ", b:" + b + ", c: " + c +"}"; }
or 要麼 ui
public String toString(){ StringBuilder sb = new StringBuilder(100); return sb.append("{a:").append(a) .append(", b:").append(b) .append(", c:").append(c) .append("}") .toString(); }
? ? spa
More importantly, given we have only 3 properties it might not make a difference, but at what point would you switch from +
concat to StringBuilder
? 更重要的是,給定只有3個屬性,這可能沒有什麼區別,可是何時您將從+
concat切換到StringBuilder
? .net