Java Arrays.copyOf(boolean[] original, int newLength)
Syntax
Arrays.copyOf(boolean[] original, int newLength) has the following syntax.
public static boolean[] copyOf(boolean[] original, int newLength)
Example
In the following code shows how to use Arrays.copyOf(boolean[] original, int newLength) method.
/* w w w .j a v a 2 s .c o m*/
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
boolean[] arr1 = new boolean[] {true, false};
System.out.println(Arrays.toString(arr1));
// copying array arr1 to arr2 with newlength as 4
boolean[] arr2 = Arrays.copyOf(arr1, 4);
// printing the array arr2
System.out.println(Arrays.toString(arr2));
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »