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)
In the following code shows how to use Arrays.copyOf(U[] original, int newLength, Class <? extends T[]> newType) method.
// w ww. j av a 2 s . c om 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.