Santoshkumar Kalasa Santoshkumar Kalasa - 1 month ago 17
Java Question

list.clone is prefered over new ArrayList(originalList)

which is standard(Prefered) way of creating clone



new ArrayList(originalList) ??


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.