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