Android Array Copy copyOf(T[] original, int newLength)

Here you can find the source of copyOf(T[] original, int newLength)

Description

Copy the specified array.

Parameter

Parameter Description
original array.
newLength new array length.

Return

copy of original.

Declaration

public static <T> T[] copyOf(T[] original, int newLength) 

Method Source Code

//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);
    }
}

Related

  1. copyArrayGrow1(Object array, Class newArrayComponentType)
  2. copyOf(Object src)
  3. copyOf(String[] obj)
  4. copyOf(String[] obj, int newSize)
  5. copyOf(T[] original)
  6. copyOf(T[] source, T[] result)
  7. copyOf(boolean[] obj)
  8. copyOf(boolean[] obj, int newSize)
  9. copyOf(byte[] obj)