美文网首页
System.arrayCopy

System.arrayCopy

作者: Djbfifjd | 来源:发表于2021-02-02 22:02 被阅读0次

一、源码

  1. Object src:源数组。
  2. int srcPos:源数组的起始位置。
  3. Object dest:目标数组。
  4. int destPos:目标数组的起始位置。
  5. int length:要 copy 的数组的长度。

二、用法示例

将源数组 srcBytes[] 从 0 位开始 copy 到目标数组 destBytes[] 中,在目标数组的第 0 位开始放置,共 copy 4 位。

public static void main(String[] args) {
    byte[] srcBytes = new byte[]{2, 4, 6, 8, 1, 3, 5, 0, 9, 7};
    byte[] destBytes = new byte[5];
    System.arraycopy(srcBytes, 0, destBytes, 0, 4);
    for (int i = 0; i < destBytes.length; i++) {
        System.out.println(destBytes[i]);
    }
}

输出:

2
4
6
8
0

相关文章

网友评论

      本文标题:System.arrayCopy

      本文链接:https://www.haomeiwen.com/subject/ksdutltx.html