Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cloning an array

 
ciaran Hurst
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesper Ottosson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic