"There is no deep copy in java," but does it matter for list of Strings?

Let's say I do:

public List<E> gimmeAList(List<E> original) {
    return new ArrayList<E>(original); // this is a shallow memcopy.
} 

I try to modify the new list, but since Strings (or any immutable object) are immutable, doing something like: gimmeAList(something).get(0).replace("a", "b"); doesn't ACTUALLY seem to change anything in either lists.

So in this case, am I allowed to just assume (for immutable objects in a list) that new ArrayList<E>(original) is guaranteed to be, for all intents and purposes, basically a deep copy?

Jon Skeet
people
quotationmark

Yes, absolutely - copying a collection of immutable objects is effectively deep, unless you do something crazy like synchronizing on the references or comparing them for reference equality (i.e. operations which depend on object identity).

people

See more on this question at Stackoverflow