Java Arrays.copyOf(U[] original, int newLength, Class <? extends T[]> newType)
Syntax
Arrays.copyOf(U[] original, int newLength, Class <? extends T[]> newType) has the following syntax.
public static <T,U> T[] copyOf(U[] original, int newLength, Class <? extends T[]> newType)
Example
In the following code shows how to use Arrays.copyOf(U[] original, int newLength, Class <? extends T[]> newType) method.
/* w w w .j a v a 2 s.co m*/
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Short shortArr[] = new Short[] { 1, 2, 15, 50, 100 };
// copy the array into another Number array
Number[] arr2 = Arrays.copyOf(shortArr, 5, Number[].class);
System.out.println(Arrays.toString(arr2));
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »