-2

why there is no clone operation for collections in Java ? There must be able to copy the contents of the collections to a new collection and modify the second collection without affecting the first one

0

1 Answer 1

3

Every collection has a constructor taking another collection as argument:

List<Foo> original = ...;
List<Foo> clone = new ArrayList<>(original);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.