Proposal: ArrayList constructor perforrmance improvement

Alan Bateman Alan.Bateman at
Tue Dec 18 17:24:41 UTC 2018

On 18/12/2018 16:44, Steve Groeger wrote:
> Hi all,
> I am proposing an enhancement to to improve its
> performance.
> ArrayList has a constructor which takes an arbitrary Collection as a
> parameter. This constructor will create an iterator over the collection
> and it will add each entry returned to the ArrayList.
> We have found that quite a lot of the time the object passed as a
> parameter is in fact an instance of ArrayList.
> In the case of an ArrayList it is possible to significantly increase the
> performance of the method since there is no need for an iterator - the
> backing array can be directly copied.
ArrayList is not final so it's possible someone has extended it to use 
something other than elementData. It might be safer to use the class 
identity rather than instanceof.


More information about the core-libs-dev mailing list