Table of Content

Create a copy of Short Array in Java


Declaration :

Explanation :

Purpose The java.util.Arrays.copyOf(short[] originalint newLength) method copies the specified array truncating or padding with zeros (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy the two arrays will contain identical values. For any indices that are valid in the copy but not the original the copy will contain (short)0. Such indices will exist if and only if the specified length is greater than that of the original array.
Parameters original ===> This is the array to be copied.
newLength ===> This is the length of the copy to be returned.
Return Value This method returns a copy of the original array truncated or padded with zeros to obtain the specified length.
Exception NegativeArraySizeException — If newLength is negative.
,NullPointerException — If original is null.

Java Program : Example

Below example will explain java.util.Arrays.copyOf() method.

Output of Program :