Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8305774

String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      In the current implementation of String.join(CharSequence, Iterable), the temp array `elems` is always initialized with a length of 8. It will cause many array recreations when the Iterable contains more than 8 elements. Furthermore, it's very common that an Iterable is also a Collection. So if the Iterable is an instance of Collection, the initial length of the array can be `((Collection<?>)elements).size()`. It will not change the current behavior even if the Collection is modified asynchronously.


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: