How can I clone an ArrayList and also clone its items in Java?
For example I have:
ArrayList<Dog> dogs = getDogs(); ArrayList<Dog> clonedList = ....something to do with dogs....
And I would expect that objects in clonedList are not the same as in dogs list.
You will need to iterate on the items, and clone them one by one, putting the clones in your result array as you go.
For that to work, obviously, you will have to get your
Dogclass to implement theCloneableinterface and override theclone()method.