How to copy Java Collections list

b has a capacity of 3, but a size of 0. The fact that ArrayList has some sort of buffer capacity is an implementation detail – it’s not part of the List interface, so Collections.copy(List, List) doesn’t use it. It would be ugly for it to special-case ArrayList.

As tddmonkey has indicated, using the ArrayList constructor which takes a collection is the way to in the example provided.

For more complicated scenarios (which may well include your real code), you may find the collections within Guava useful.

Leave a Comment