Java system.arraycopy Usage Instructions

Source: Internet
Author: User

Java system.arraycopy Usage Instructions

The Java.lang.System.arraycopy () method copies the array of the specified source array, starting at the specified position, to the specified position in the destination array.

The following is the source code declaration for System.arraycopy:

public static void Arraycopy (object src, int srcpos, object dest, int destpos, int length)
Code Explanation:
Object src: Original array
int Srcpos: Starting from the beginning of the metadata
Object dest: Destination array
int Destpos: Starting position of the target array
int length : The length of the array to copy

For example: We have an array of data byte[] srcbytes = new byte[]{2,4,0,0,0,0,0,10,15,50}; Source Array

byte[] destbytes = new BYTE[5]; Target array

We use System.arraycopy to convert (copy)

System.arraycopy (Srcbytes,0,destbytes, 0,5)
The above code is: Create a one-dimensional empty array, the total length of the array is 12 bits, and then copy the value from the Srcbytes source array from 0 bits to 5th bits into the Destbytes destination array, starting at the No. 0 bit of the destination array.
Then this line of code should run as 2,4,0,0,0,
1         byte[] Srcbytes =New byte[]{2,4,0,0,0,0,0,Ten, the, -};2         byte[] Destbytes =New byte[5];3System.arraycopy (Srcbytes,0, Destbytes,0,5); 4          for(inti =0;i< destbytes.length;i++){5System. out. Print (" -"+destbytes[i]);6}

Operating result: 2-> 4-> 0-> 0-> 0

Java system.arraycopy Usage Instructions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.