diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 91cde23bfec..92477e8a8b2 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -3930,11 +3930,13 @@ public static String join(final boolean[] array, final char delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(array.length * 5 + array.length - 1); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -4007,11 +4009,13 @@ public static String join(final byte[] array, final char delimiter, final int st if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -4084,11 +4088,13 @@ public static String join(final char[] array, final char delimiter, final int st if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(array.length * 2 - 1); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -4161,11 +4167,13 @@ public static String join(final double[] array, final char delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -4238,11 +4246,13 @@ public static String join(final float[] array, final char delimiter, final int s if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -4315,11 +4325,13 @@ public static String join(final int[] array, final char delimiter, final int sta if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -4601,11 +4613,13 @@ public static String join(final long[] array, final char delimiter, final int st if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -4664,17 +4678,7 @@ public static String join(final Object[] array, final char delimiter) { * @since 2.0 */ public static String join(final Object[] array, final char delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - final StringJoiner joiner = newStringJoiner(delimiter); - for (int i = startIndex; i < endIndex; i++) { - joiner.add(toStringOrEmpty(array[i])); - } - return joiner.toString(); + return join(array, String.valueOf(delimiter), startIndex, endIndex); } /** @@ -4826,11 +4830,13 @@ public static String join(final short[] array, final char delimiter, final int s if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringBuilder stringBuilder = new StringBuilder(); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + stringBuilder + .append(array[i]) + .append(delimiter); } - return joiner.toString(); + return stringBuilder.substring(0, stringBuilder.length() - 1); } /** @@ -5522,10 +5528,6 @@ public static String mid(final String str, int pos, final int len) { return str.substring(pos, pos + len); } - private static StringJoiner newStringJoiner(final char delimiter) { - return new StringJoiner(String.valueOf(delimiter)); - } - /** *