System中的常用方法

来源:互联网 发布:淘宝怎么看在线人数 编辑:程序博客网 时间:2024/05/16 02:05

public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)

        从源数组的指定位置复制一个数组到目标数组的指定位置。从src参数代表的源数组中复制一个子序列到dest参数代表的数组中。子序列的长度等于length参数的值。子序列从源数组的srcPos处开始,到srcPos+length-1为止,子序列放在目标数组的从destPos处开始,到destPos+length-1为止。

如果参数src和dest代表的是同一个数组对象,则子序列首先被存放在临时数组中,然后在将临时数组中的序列复制到目标数组中。

示例:

public void arrayCopyTest(){ String[] str1 = {"a","b","c","d","e","f", "", "", "", ""};                System.arraycopy(str1, 1, str1, 6, 3); for(String str : str1){    System.out.print(str + ","); }}输出:a,b,c,d,e,f,b,c,d,,


0 0
原创粉丝点击