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