Proposal: ArrayList constructor perforrmance improvement
Stuart Marks
stuart.marks at oracle.com
Tue Dec 18 22:01:30 UTC 2018
On 12/18/18 9:23 AM, Martin Buchholz wrote:
> The blessed solution to the list copy problem is probably List.copyOf
> https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#copyOf(java.util.Collection)
> which might do the optimization you're hoping for.
List.copyOf is fine, but note that it returns an instance of an unmodifiable
List. The main optimization it does is that if it's asked to make a copy of an
already-unmodifiable list, it simply returns its argument.
If you want an actual ArrayList instead of an unmodifiable list, of course
you'll have to use the ArrayList copy constructor or some variation.
s'marks
More information about the core-libs-dev
mailing list