Proposal: ArrayList constructor perforrmance improvement

Martin Buchholz martinrb at google.com
Wed Dec 19 13:47:29 UTC 2018


Thanks as always to Jason, our master Historian.

On Wed, Dec 19, 2018 at 2:14 AM Steve Groeger <GROEGES at uk.ibm.com> wrote:

>
> Yes, the intent was to leave the backing array the same size in order to
> avoid to have the resize of it when a new element is added.
> So, if someone wanted to reduce the size of the backing array then they
> could use the ArrayList.trimToSize() method.


If you knew you wanted to add exactly one element after making a copy, an
(distasteful but effective) performance hack might be to add the element to
the source ArrayList, copy using ArrayList(Collection) and then remove the
element from the source.


More information about the core-libs-dev mailing list