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 System.arrayCopy() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System.arrayCopy()" Watch "System.arrayCopy()" New topic


Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
I am trying to compile this but it won't compile.

int verylong;
int notsolong;

String[] aa = new String[verylong];
String[] bb = new String[notsolong];

// fill aa with Strings

System.arrayCopy(aa, 0, bb, 0, notsolong);

According to the API, this method is
System.arrayCopy(Object src, int srcbegin, Object dest, int destbegin, int howmany)
String arrays are Objects, so this should work, I think. What do I have to do?
Object obOne = aa;
Object obTwo = bb;
or something like that???
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Typically when something does not compile, you get an error message. The text of this message may contain useful clues about the nature of the problem. Even if you don't understand what the error message means yourself, it's useful to other people who you might ask for help. So: what does the error message say?

"I'm not back." - Bill Harding, Twister
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

'arrayCopy' method name is wrong. The correct method is,

System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)

- Marimuthu Madasamy
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Usually I give more explanation about the error message, but this time I forgot to do that, it seems. My computer gives error messages in Japanese, so instead of copying the error message, I give it kind of an English translation.

System.arraycopy()! I can't believe I just spelled it wrong! I spelled it arrayCopy! I must have been really tired or something. Usually methods in java, when they are a compound of two or more words, have the first word in all small letters, and capitalize the other words, like Integer.intValue() etc. I thought String.substring() should be String.subString() until I thought about it and realized that sub is not really a word. But array and copy are both words, so I expected arrayCopy, not arraycopy.

Well, thanks anyway.
I agree. Here's the link:
subject: System.arrayCopy()
It's not a secret anymore!