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

System.arrayCopy()

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Marimuthu Madasamy
Ranch Hand
Posts: 72
Java Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'arrayCopy' method name is wrong. The correct method is,

System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic