Home > Java > javaTutorial > System.arraycopy method usage

System.arraycopy method usage

angryTom
Release: 2020-02-13 17:45:33
Original
4718 people have browsed it

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)
Copy after login

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);
        }
    }
}
Copy after login

Console output result:

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

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template