| Author |
Shallow copy of array
|
Denis Yuzvyk
Greenhorn
Joined: Dec 06, 2004
Posts: 22
|
|
I have array of my classes: MyClass [] arr = new MyClass [] {new MyClass(), new MyClass ()}; how to make shalow copy of arr? arr.clone() will be enough?
|
 |
gaurav abbi
Ranch Hand
Joined: Jan 05, 2007
Posts: 108
|
|
ya doing MyClass[] arrClone = (MyClass[])arr.clone(); will be enough.
|
thanks,<br />gaurav abbi
|
 |
Abdul Rehman
Ranch Hand
Joined: Nov 07, 2006
Posts: 65
|
|
|
All arrays in Java, irrespective of their types, inter se implement java.io.Serializable & java.lang.Cloneable. Thus calling clone() on a reference to an array object will not throw a CloneNotSupportedException, albeit, you will have to catch the exception (as it is a checked exception).
|
SCJP 5.0 (100%)
|
 |
 |
|
|
subject: Shallow copy of array
|
|
|