Java ArrayList copy without creating a new array

I have a List implementation (not mine) with an underlying array.

The implementation does not give access to the array directly, but only through the LIST INTERFACE methods that are implemented (just as an ArrayList implementation)

At some point, i will not able to work with this list (because of its implementation), but i will need to access (READ only) the data (underlying array).

Is there a way this can be achieved? Can a new ArrayList be created using the underlying array of the old one, without the creation of an ARRAY COPY?

Jon Skeet
people
quotationmark

You're going to have to have a new array to back the ArrayList anyway - so why is it a problem that it calls c.toArray()? The only inefficiency would be if it ends up in the branch calling Arrays.copyOf.

people

See more on this question at Stackoverflow