Santoshkumar Kalasa Santoshkumar Kalasa - 1 year ago 86
Java Question

list.clone is prefered over new ArrayList(originalList)

which is standard(Prefered) way of creating clone



new ArrayList(originalList) ??

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download