-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
  • 101
  • 1
  • 4

1 Answers1

3

Every collection has a constructor taking another collection as argument:

List<Foo> original = ...;
List<Foo> clone = new ArrayList<>(original);
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255