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