java - Which class to use for this static method, StringBuffer or StringBuilder? -
for following code, class should use in static method, stringbuilder
or stringbuffer
? based on api, stringbuffer
thread-safe, stringbuilder
not.
public static string getstring(int[] arrs) { stringbuilder sb = new stringbuilder(); //1 stringbuffer sb = new stringbuffer(); //2 (int : arrs) { sb.append(i); } return sb.tostring(); }
it's method-local variable, won't have concurrent access there... use stringbuilder
Comments
Post a Comment