jQuery in Action, 2nd edition*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cloning an array" Watch "cloning an array" New topic
Author

cloning an array

ciaran Hurst
Greenhorn

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
thanks.
------------------
regards
Ciaran


regards<BR>Ciaran
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();
W.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cloning an array