Arrays 避免阵列回路声纳问题:system.arraycopy

Arrays 避免阵列回路声纳问题:system.arraycopy,arrays,sonarqube,Arrays,Sonarqube,我想使用SysteM.arraycopy使下面的方法更快。但据我所知,Arraycopy不能涉及任何这样复杂的逻辑 for (int c = 0; c < newRow.length && c < target[r].length; ++c) { target[r][c] = newRow[c]; } for(int c=0;c

我想使用SysteM.arraycopy使下面的方法更快。但据我所知,Arraycopy不能涉及任何这样复杂的逻辑

for (int c = 0; c < newRow.length && c < target[r].length; ++c)
{
    target[r][c] = newRow[c];
}
for(int c=0;c

因此,欢迎任何帮助。提前感谢。

您可以使用
System.arraycopy
重新编写。 这是这样的:

  • 您想从
    newRow
  • 您想从索引0开始复制到
    target[r]
  • 您最多要复制
    newRow.length
    target[r].length
    元素,以较小者为准
像这样:

System.arraycopy(newRow, 0, target[r], 0, Math.min(newRow.length, target[r].length));