devxlogo

Using System.arraycopy(…..)

Using System.arraycopy(…..)

When you need the contents of an array for processing, you no longer have to write loops to copy the required contents from the main to the sub-array. Java has provided an API for this task?the arraycopy method in the System class.

The method takes five arguments:

  1. src: The source array.
  2. srcPosition: The position in the source from where you wish to begin copying.
  3. des: The destination array.
  4. desPosition: The position in the destination array to where the copy should start.
  5. length: The number of elements to be copied.

This method throws a NullPointerException if either of src or des are null.

It also throws an ArrayStoreException in the following cases:

  • If the src is not an array.
  • If the des is not an array.
  • If src and des are arrays of different data types.
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist