File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shallow copy of array

 
Denis Yuzvyk
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya doing
MyClass[] arrClone = (MyClass[])arr.clone();

will be enough.
 
Abdul Rehman
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic