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:
- src: The source array.
- srcPosition: The position in the source from where you wish to begin copying.
- des: The destination array.
- desPosition: The position in the destination array to where the copy should start.
- 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.