@Test public void test() throws Exception { String[] strings = new String[] { "aaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbb" }; benchmark.doSomething("join:", () -> StringUtils.build(",", "{", "}", strings)); benchmark.doSomething("join1:", () -> join1(",", "{", "}", strings)); benchmark.doSomething("join2:", () -> join2(",", "{", "}", strings)); }
public static String build(String delimiter, String prefix, String suffix, String... strings) { int len = prefix.length() + suffix.length() + (strings.length - 1) * delimiter.length(); for (String str : strings) { len += str.length(); } StringBuilder result = new StringBuilder(len); result.append(prefix); for (String str : strings) { result.append(str).append(delimiter); } if (result.length() > prefix.length()) { result.deleteCharAt(result.length() - 1); } result.append(suffix); return result.toString(); }
StringUtils { public static String build(String delimiter, String prefix, String suffix, String... strings) { int len = prefix.length() + suffix.length() + (strings.length - 1) * delimiter.length(); for (String str : strings) { len += str.length(); } StringBuilder result = new StringBuilder(len); result.append(prefix); for (String str : strings) { result.append(str).append(delimiter); } if (result.length() > prefix.length()) { result.deleteCharAt(result.length() - 1); } result.append(suffix); return result.toString(); } }
StringUtils { public static String build(String delimiter, String prefix, String suffix, String... strings) { int len = prefix.length() + suffix.length() + (strings.length - 1) * delimiter.length(); for (String str : strings) { len += str.length(); } StringBuilder result = new StringBuilder(len); result.append(prefix); for (String str : strings) { result.append(str).append(delimiter); } if (result.length() > prefix.length()) { result.deleteCharAt(result.length() - 1); } result.append(suffix); return result.toString(); }  }
StringUtils { public static String build(String delimiter, String prefix, String suffix, String... strings) { int len = prefix.length() + suffix.length() + (strings.length - 1) * delimiter.length(); for (String str : strings) { len += str.length(); } StringBuilder result = new StringBuilder(len); result.append(prefix); for (String str : strings) { result.append(str).append(delimiter); } if (result.length() > prefix.length()) { result.deleteCharAt(result.length() - 1); } result.append(suffix); return result.toString(); }  static boolean isEmpty(final String text); static boolean isNotEmpty(final String text); static boolean isBlank(final String text); static boolean isNotBlank(final String text); static int length(final String text); static String[] split(final String str, final String separatorChars); static String lowerWord(CharSequence cs, char c); static int asciiSizeInBytes(long v); static String join(String... strings); static String build(String delimiter, String prefix, String suffix, String... strings); static byte[] utf8Bytes(CharSequence str); static byte[] bytes(CharSequence str); static byte[] bytes(CharSequence str, Charset charset); static String format(String str, Object... arguments); static String readString(InputStream inputStream); static String readString(InputStream inputStream, Charset charset); static String readString(Reader reader); }
StringUtils { public static String build(String delimiter, String prefix, String suffix, String... strings) { int len = prefix.length() + suffix.length() + (strings.length - 1) * delimiter.length(); for (String str : strings) { len += str.length(); } StringBuilder result = new StringBuilder(len); result.append(prefix); for (String str : strings) { result.append(str).append(delimiter); } if (result.length() > prefix.length()) { result.deleteCharAt(result.length() - 1); } result.append(suffix); return result.toString(); }  static boolean isEmpty(final String text); static boolean isNotEmpty(final String text); static boolean isBlank(final String text); static boolean isNotBlank(final String text); static int length(final String text); static String[] split(final String str, final String separatorChars); static String lowerWord(CharSequence cs, char c); static int asciiSizeInBytes(long v); static String join(String... strings); static String build(String delimiter, String prefix, String suffix, String... strings); static byte[] utf8Bytes(CharSequence str); static byte[] bytes(CharSequence str); static byte[] bytes(CharSequence str, Charset charset); static String format(String str, Object... arguments); static String readString(InputStream inputStream); static String readString(InputStream inputStream, Charset charset); static String readString(Reader reader); static final String EMPTY; static final String SPACE; static final String LF; static final String CR; static final String COMMA; static final String[] EMPTY_STRING_ARRAY; }