Home  >  Article  >  Java  >  System.arraycopy method usage

System.arraycopy method usage

angryTom
angryTomOriginal
2020-02-13 17:45:334658browse

System.arraycopy method usage

System.arraycopy method uses

System provides a static method arraycopy(), we can use it to Implement copying between arrays.

The function prototype is:

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

Parameter explanation:

src: source array;

srcPos: the starting point of the source array to be copied Position;

dest: destination array;

destPos: the starting position where the destination array is placed;

length: the length of the copy.

Note: Both src and dest must be of the same type or arrays that can be converted.

(Related video tutorial sharing: java video tutorial)

Test class:

public class SysTest {
 
    public static void main(String[] args) {
        String src[] = new String[] { "hello", "huang", "bao", "kang" };
        String dest[] = new String[5];
        System.arraycopy(src, 0, dest, 0, 4);
        for (String str : dest) {
            System.out.println(str);
        }
        System.out.println("=========华丽的分割线=========");
        System.arraycopy(src, 0, src, 1, 3);
        for (String str : src) {
            System.out.println(str);
        }
    }
}

Console output result:

hello
huang
bao
kang
null
=========华丽的分割线=========
hello
hello
huang
bao

The above is the detailed content of System.arraycopy method usage. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn