I'm not sure if the following will result in deep or shallow copy?
public void viewImages(final String[] instancesFilename) { String[] instances = (String[])instancesFilename.clone(); } Is there a simple and fast way to deep copy a string array?
Strings in Java are imutable(Can't change their value). So there is no detectable difference between a deep and shallow copy when copying strings.
And just to further reference: The copy will be shallow but that should not be a problem since strings are imutable.
Oh and funny fact: Strings can't be cloned with the clone method, so if you try to do a deep copy of strings with the clone method, you will get a CloneNotSupportedException.
String[], not String. The elements of instancesFilename could be changed later from the outside, so the OP wants to create a copy of the array.intern()'d, which would make kind of a shallow copy :\The array class also has the copyOf method. This is generally what I use for creating copies of arrays. Heres and explanation of all of the differences: http://forum.codecall.net/topic/49450-copying-arrays/
Here is an interesting article discussing using serialization to make deep copies.
The objects in the call graph do need to support serialization however in many business types of 3 Tier applications, that necessity is there.
The article provides a discussion of deep copy and shallow copy with some diagrams.