If you check the API for ArrayList.clone(), you'll learn it's a shallow copy. A new ArrayList object is returned, but it contains the same elements (not new copies) of the original ArrayList.
To see how this works, try this little program:
The output is:
list and copy are same object? false item 0 is same object? true item 0 is equals? true item 1 is same object? true item 1 is equals? true item 2 is same object? true item 2 is equals? true // here we do String s = list.get(0); s = new String("different"); item 0 is same object? true item 0 is equals? true // here we did list.set(0, new String("new")); item 0 is same object? false item 0 is equals? false [ May 28, 2008: Message edited by: Stevi Deter ]
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James