Java中System.arraycopy()具有什么功能呢?
下文笔者将讲述System.arraycopy()方法的功能简介说明,如下所示:
System.arraycopy()方法的功能:
用于复制指定的源数组的数组
从指定的位置开始,到目标数组的指定位置
System.arraycopy()方法的语法:
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) -------参数说明------- src:源数组 srcPos:源数组要复制的起始位置 dest:目的数组 destPos:目的数组放置的起始位置 length:复制的长度 -------返回值说明----- 此方法无返回值 注意事项: src和dest都必须是同类型或可以进行转换类型的数组例:
package com.java265.other;
import java.util.Arrays;
/*
*数组复制测试示例分享
*/
public class TestClass {
public static void main(String[] args) {
int[] ids = { 1, 2, 3, 4, 5 };
System.out.println(Arrays.toString(ids)); // [1, 2, 3, 4, 5]
System.arraycopy(ids, 0, ids, 3, 2);
System.out.println(Arrays.toString(ids)); // [1, 2, 3, 1, 2]
int[] ids2 = new int[6];
System.arraycopy(ids, 1, ids2, 0, 3);
System.out.println(Arrays.toString(ids2)); // [2, 3, 1, 0, 0, 0]
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


