5

I'm trying to convert some C# code to Java and I came across a line that calls this method:

Array.Copy(
    frames[row],
    0,
    concatenated,
    row*frames[row].Length,
    frames[row].Length);

The signature of the C# method looks like this:

Array.Copy(
    Array sourceArray,
    int sourceIndex,
    Array destinationArray,
    int destinationIndex,
    int length)

I'm trying to find way to do the same in Java with no luck. How can I mimic the same behavior in Java?

2
  • I should probably mention that the line preceding this one is a loop: for (int row = 0; row < rows; row++) Commented May 15, 2012 at 2:57
  • 1
    You have trouble writing for(i=sourceIndex; i<dest+len;i++)... loop or trying to find some optimized code? Commented May 15, 2012 at 2:57

1 Answer 1

9

Did you try to System.arraycopy() ?

Example:

 char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e', 'i', 'n', 'a', 't', 'e', 'd' };
 char[] copyTo = new char[10];

 System.arraycopy(copyFrom, 1, copyTo, 2, 8);
 System.out.println(new String(copyTo));

The output will be:

  ecaffein
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.