0

which is standard(Prefered) way of creating clone

list.clone()

or

new ArrayList(originalList) ??

Santoshkumar Kalasa
  • 477
  • 1
  • 5
  • 15

1 Answers1

2

Use new ArrayList(originalList) instead of list.clone() because for list you have to iterate for all object of list and clone individually.

This will work fine for Strings, but it is worth noting that ArrayList.clone will perform a shallow copy, so if there were mutable objects in the list, they will not be cloned and changing one in one list will change that one in the other list as well.

bNd
  • 7,512
  • 7
  • 39
  • 72