Java Array class copyOf(short[] original, int newLength) example
Array class copyOf(short[] original, int newLength) method example
Array class copyOf(short[] original, int newLength) method example. This example shows you how to use copyOf(short[] original, int newLength) method.This method Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
Here is the code:-
/**
* @Program that Copies the specified array, truncating or padding with zeros
* (if necessary) so the copy has the specified length.
* Copy7Array.java
* Author:-RoseIndia Team
* Date:-15-May-2008
*/
import java.util.*;
public class Copy7Array {
public static void main(String[] args) {
//creating a short array
short j[]={34,46,78,7,89};
//Copies the specified short array,
short b1[]=Arrays.copyOf(j,5);
for (int i=0;i<b1.length;i++)
//Displaying the Copied short Array
System.out.println("The Copied short array is:-" + b1[i]);
}
} |
Output of the program:-
The Copied short array is:-34
The Copied short array is:-46
The Copied short array is:-78
The Copied short array is:-7
The Copied short array is:-89 |
|