/** * @author djkim */ public class StringBuilderPool { private static final Pools.SynchronizedPool<StringBuilder> pool = new Pools.SynchronizedPool<>(10);
@NonNull public static StringBuilder obtain() { StringBuilder instance = pool.acquire(); return (instance != null) ? instance : new StringBuilder(80); }
public static void recycle(@NonNull StringBuilder sb) { sb.setLength(0); pool.release(sb); }
/// if params.length == 0, return null @Nullable public static String concat(Object... params) { String result = null;
if (params.length > 0) { StringBuilder sb = obtain(); for (Object object : params) { sb.append(object); } result = sb.toString(); recycle(sb); }