-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

nandy
  • 81
  • 1
  • 3

1 Answers1

3

Every collection has a constructor taking another collection as argument:

List<Foo> original = ...;
List<Foo> clone = new ArrayList<>(original);
JB Nizet
  • 657,433
  • 87
  • 1,179
  • 1,226