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

Reply via email to