This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Shallow  copy of array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Shallow  copy of array" Watch "Shallow  copy of array" New topic
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%)
 
Don't get me started about those stupid light bulbs.
 
subject: Shallow copy of array
 
Similar Threads
returning an array
Arrays& GCs
How to create multidimension array using for each loop?
exceptions and type casting confusion
how to write constructor?