2012-05-15 56 views
4

我试图将一些C#代码转换为Java,并且遇到了一条调用此方法的行:Java版本的c#Array.Copy(Array sourceArray,int sourceIndex,Array destinationArray,int destinationIndex,int length)

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

的C#方法的签名如下:

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

我试图找到办法,没有运气做同样在Java中。我怎样才能在Java中模仿相同的行为?

+0

我应该提到,这一个在前的行是一个循环:for(INT行= 0;行<行;行++ ) – adam0101

+1

您在编写'for(i = sourceIndex; i

+1

你想'System.arraycopy' – mikera

回答

4

你试过System.arraycopy()吗?

实施例:

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)); 

的输出将是:

ecaffein 
+0

谢谢!我知道它必须在某个地方。 – adam0101

+0

不客气。 – nnhthuan

相关问题