Well-off accompany you to learn the copy operation of the Java--------array

Source: Internet
Author: User

API provides a lot of methods for program developers to use, the next two will share with you two common array operation methods, today to introduce the first method- the copy operation of the array .

Example: Testjava4_4.java

01//The following procedure describes the copy operation of the array

public class Testjava4_4

03 {

public static void Main (string[] args)

05 {

a1[int] = {1,2,3,4,5}; Declares two integer arrays A1, A2, and initializes them statically

-int a2[] = {9,8,7,6,5,4,3};

System.arraycopy (a1,0,a2,0,3); Operations that perform array copies

System.out.print ("contents of the A1 array:");

Ten for (int i=0;i<a1.length;i++)//output A1 The contents of the array

One System.out.print (a1[i]+ "");

System.out.println ();

13

System.out.print ("contents of the A2 array:");

(int i=0;i<a2.length;i++)//Output a2 the contents of the array

System.out.print (A2[i] + "");

System.out.println ("\ n Array copy complete! ");

18}

19}

Output Result:

A1 the contents of the array: 1 2 3 4 5

A2 the contents of the array: 1 2 3 6 5 4 3

Array copy complete!

System.arraycopy (source,0,dest,0,x): The meaning of the statement is: Copy the source array from the subscript 0 starting from the X element to the target array, from the target array of subscript 0 corresponding to the location to start access.

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.