System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
arraycopy()方法的参数含义如下:
src:源数组
srcPos:从源数组中复制的起始位置
dest:目标数组
destPos:目标数组插入的起始位置
length:从源数据复制的元素个数
代码示例:
public class TestArrayCopy
{
public static void test()
{
String[] a = {"a1","a2","a3","a4"};
String[] b = {"b1","b2","b3","b4","b5","b6"};
System.arraycopy(a, 0, b, 2, 3);
for (String s:b)
{
System.out.print(s + " ");
}
}
public static void main(String[] args)
{
TestArrayCopy.test();
}
}
输出结果如下:
b1 b2 a1 a2 a3 b6
分享到:
评论