Java Array Copy copyOf(final U[] original, final int newLength, final Class newType)

Here you can find the source of copyOf(final U[] original, final int newLength, final Class newType)

Description

Copy of.

License

Open Source License

Parameter

Parameter Description
T the generic type
U the generic type
original the original
newLength the new length
newType the new type

Return

the t[]

Declaration





public static <T, U> T[] copyOf(final U[] original,
        final int newLength, final Class<? extends T[]> newType) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**// w  w w .  jav  a  2s . co  m
     * Copy of.
     *
     * @param <T>
     *            the generic type
     * @param <U>
     *            the generic type
     * @param original
     *            the original
     * @param newLength
     *            the new length
     * @param newType
     *            the new type
     * @return the t[]
     */
    // object[] -> string[]
    // String[] stringArray = Arrays.copyOf(objectArray, objectArray.length,
    // String[].class);
    // Arrays.asList(Object_Array).toArray(new String[Object_Array.length]);
    public static <T, U> T[] copyOf(final U[] original,
            final int newLength, final Class<? extends T[]> newType) {
        return Arrays.copyOf(original, newLength, newType);
    }
}

Related

  1. copyBytes(byte[] data, int from, int to)
  2. copyExcept(E[] orig, E excludedElem)
  3. copyIfExceeded(int[] arr, int len)
  4. copyIntoBigger(int[] array, int newSize, int defaultValue)
  5. copyOf(boolean[] t)
  6. copyOf(T[] array)
  7. copyOf(T[] array, int count)
  8. copyOf(T[] original)
  9. copyOf(T[] original)