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 How do to use ArrayCopy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
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: 24195

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?
It's not a secret anymore!