On Mon, 10 Apr 2023 03:04:20 GMT, Chen Liang <li...@openjdk.org> wrote:
>> @liach Working on that. > > @yuantj Alternatively, you can probably try working on the `toArray` result > of a collection than to allocate a new String array. This might be more > efficient for some implementations like ArrayList as well, in addition to > benefiting concurrent collections. @liach Did you mean this? public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) { if (elements instanceof Collection<?> c) { try { return String.join(delimiter, c.toArray(new CharSequence[0])); } catch (ArrayStoreException e) { throw new ClassCastException(e.getMessage()); } } else { // old implementations for non-collection iterables. } } ------------- PR Comment: https://git.openjdk.org/jdk/pull/13383#issuecomment-1501340839