File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes cloning an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cloning an array" Watch "cloning an array" New topic

cloning an array

ciaran Hurst

Joined: Oct 30, 2001
Posts: 9
could some body please tell me how to clone a simple integer array? Do i have to construct a class that implements cloneable

Jesper Ottosson
Ranch Hand

Joined: Mar 21, 2000
Posts: 51
If you really need to use the clone method, I believe you will have to do some manual construct, but otherwise there's the handy System.arraycopy()
// Jesper
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
No you do not have to. Array implements interface Cloneable.
You just have to call clone on your array:
int firstArray[] = { 0,1, 2, 3, 4 };
int secondArray[] = (int[])firstArray.clone();
I agree. Here's the link:
subject: cloning an array
It's not a secret anymore!