Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do to use ArrayCopy?

 
Travis Gn
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried copying arrays:
array1 = array2;
It's not working. Someone said to copy an array you need to use Arraycopy I don't know how to use this? Any help?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assigning array1=array2 will, as you have probably already figured out, just give you two pointers to the same array.
To copy any array, you can use the static method arraycopy() in the java.lang.System class, like this:

To find out what the various parameters mean, see the Javadoc for this method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic