Here you can find the source of copyOf(T[] original, int newLength)
Parameter | Description |
---|---|
original | array. |
newLength | new array length. |
public static <T> T[] copyOf(T[] original, int newLength)
//package com.java2s; public class Main { /** /* ww w . j ava 2 s. c om*/ * Copy the specified array. * @param original array. * @param newLength new array length. * @return copy of original. */ public static <T> T[] copyOf(T[] original, int newLength) { T[] copy = (T[]) new Object[newLength]; System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); return copy; } /** * Copy the specified array. * @param original array. * @return copy of original. */ public static <T> T[] copyOf(T[] original) { return (T[]) copyOf(original, original.length); } }