Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes How do to use ArrayCopy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do to use ArrayCopy?" Watch "How do to use ArrayCopy?" New topic

How do to use ArrayCopy?

Travis Gn

Joined: Sep 11, 2003
Posts: 19
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?

I need more help!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: How do to use ArrayCopy?
jQuery in Action, 3rd edition