Java Array Clone clone(final T[] array)

Here you can find the source of clone(final T[] array)

Description

Shallow clones an array and handling null.
The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.

License

Open Source License

Parameter

Parameter Description
T the component type of the array
array the array to shallow clone, may be <code>null</code>

Return

the cloned array or null

Declaration

public static <T> T[] clone(final T[] array) 

Method Source Code

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

public class Main {
    /**/*from  w  w w .j a  va  2  s  .  c o  m*/
     * Shallow clones an array and handling <code>null</code>.<br>
     * The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.
     *
     * @param <T>
     *            the component type of the array
     * @param array
     *            the array to shallow clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static <T> T[] clone(final T[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static long[] clone(final long[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static int[] clone(final int[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static short[] clone(final short[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static char[] clone(final char[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static byte[] clone(final byte[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static double[] clone(final double[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static float[] clone(final float[] array) {
        return array != null ? array.clone() : null;
    }

    /**
     * Clones an array and handling <code>null</code>.
     *
     * @param array
     *            the array to clone, may be <code>null</code>
     * @return the cloned array or <code>null</code>
     */
    public static boolean[] clone(final boolean[] array) {
        return array != null ? array.clone() : null;
    }
}

Related

  1. clone(final byte[] array)
  2. clone(final double[][] array)
  3. clone(final int[] original)
  4. clone(final T[] array)
  5. clone(final T[] array)
  6. clone(float[] array)
  7. clone(float[] f)
  8. clone(float[][] array)
  9. clone(int[] a)