Java Array class copyOf(int[] original, int newLength) example
Array class copyOf(int[] original, int newLength) method example
Array class copyOf(int[] original, int newLength) method example. This example shows you how to use copyOf(int[] 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.
* Copy5Array.java
* Author:-RoseIndia Team
* Date:-15-May-2008
*/
import java.util.*;
public class Copy5Array {
public static void main(String[] args) {
//creating a Integer array
int j[]={34,46,78,7,89};
//Copies the specified Integer array,
int b1[]=Arrays.copyOf(j,5);
for (int i=0;i<b1.length;i++)
//Displaying the Copied Float Array
System.out.println("The Copied Integer array is:-" + b1[i]);
}
} |
Output of the program:-
The Copied Integer array is:-34
The Copied Integer array is:-46
The Copied Integer array is:-78
The Copied Integer array is:-7
The Copied Integer array is:-89 |
|