Home> Java> javaTutorial> body text

System.arraycopy method usage

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

System.arraycopy method usage

System.arraycopy method uses

System provides a static methodarraycopy(), 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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!