arraycopy(System类的静态方法)
public static void arraycopy(
Object src,
int srcPos,
Object dest,
int destPos,
int length)
简述
从指定源数组中复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束。
参数:
src - 源数组。
srcPos - 源数组中的起始位置。
dest - 目标数组。
destPos - 目标数据中的起始位置。
length - 要复制的数组元素的数量。
例
public static void main(String[] args) {int []one={1,2,3,0,0,0,0};int []two={4,5,6,7};//将数组two中元素从索引0开始长度为4,复制到数组one中从索引3开始System.arraycopy(two,0,one,3,4);System.out.println("数组one为:"+Arrays.toString(one));System.out.println();//数组one现在为[1, 2, 3, 4, 5, 6, 7]//将数组one中的索引从0开始长度为3,复制到数组one的索引从4开始System.arraycopy(one,0,one,4,3);System.out.println("数组one为:"+Arrays.toString(one));}
Tips:arraycopy是System类的静态方法,使用System.arraycopy(xxx)调用
ArrayList的remove()和add(int ?,object ?)都是是根据此方法进行的操作。