aspose file tools*
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 Java 8 in Action this week in the Java 8 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%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shallow copy of array
 
Similar Threads
Arrays& GCs
returning an array
How to create multidimension array using for each loop?
how to write constructor?
exceptions and type casting confusion