Java Array Clone clone(Object[] array)

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

Description

Shallow clones an array returning a typecast result and handling null.

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

This method returns null for a null input array.

License

Apache License

Parameter

Parameter Description
array the array to shallow clone, may be <code>null</code>

Return

the cloned array, null if null input

Declaration

public static Object[] clone(Object[] array) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*  ww w. j  a  v  a2  s . c  o m*/
     * <p>Shallow clones an array returning a typecast result and handling
     * <code>null</code>.</p>
     *
     * <p>The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.</p>
     *
     * <p>This method returns
     * <code>null</code> for a
     * <code>null</code> input array.</p>
     *
     * @param array the array to shallow clone, may be <code>null</code>
     * @return the cloned array, <code>null</code> if <code>null</code> input
     */
    public static Object[] clone(Object[] array) {
        if (array == null) {
            return null;
        }
        return (Object[]) array.clone();
    }
}

Related

  1. clone(int[] in)
  2. clone(int[] src)
  3. clone(int[] src, int[] dest)
  4. clone(Object[] array)
  5. clone(Object[] array)
  6. clone(Object[] source)
  7. clone(Object[] src, Object[] trg)
  8. clone(String[] array)
  9. clone(T[] array)