Java Array Copy copy(final boolean[] array)

Here you can find the source of copy(final boolean[] array)

Description

Creates a new copy of the given array.

License

Open Source License

Parameter

Parameter Description
array The array to copy.

Return

A copy of the given array.

Declaration

public static boolean[] copy(final boolean[] array) 

Method Source Code


//package com.java2s;
/*/* ww w  . ja  v a2 s.  c  o  m*/
 * File:                ArrayUtil.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 * 
 * Copyright September 23, 2010, Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the U.S. Government. Export
 * of this program may require a license from the United States Government.
 * See CopyrightHistory.txt for complete details.
 * 
 */

import java.util.Arrays;

public class Main {
    /**
     * Creates a new copy of the given array.
     *
     * @param   array
     *      The array to copy.
     * @return
     *      A copy of the given array.
     */
    public static boolean[] copy(final boolean[] array) {
        if (array == null) {
            return null;
        } else {
            return Arrays.copyOf(array, array.length);
        }
    }

    /**
     * Creates a new copy of the given array.
     *
     * @param   array
     *      The array to copy.
     * @return
     *      A copy of the given array.
     */
    public static int[] copy(final int[] array) {
        if (array == null) {
            return null;
        } else {
            return Arrays.copyOf(array, array.length);
        }
    }

    /**
     * Creates a new copy of the given array.
     *
     * @param   array
     *      The array to copy.
     * @return
     *      A copy of the given array.
     */
    public static long[] copy(final long[] array) {
        if (array == null) {
            return null;
        } else {
            return Arrays.copyOf(array, array.length);
        }
    }

    /**
     * Creates a new copy of the given array.
     *
     * @param   array
     *      The array to copy.
     * @return
     *      A copy of the given array.
     */
    public static double[] copy(final double[] array) {
        if (array == null) {
            return null;
        } else {
            return Arrays.copyOf(array, array.length);
        }
    }

    /**
     * Creates a new copy of the given array. Does not copy the elements.
     *
     * @param   <T>
     *      The type of data in the array.
     * @param   array
     *      The array to copy. Does not copy the elements.
     * @return
     *      A copy of the given array.
     */
    public static <T> T[] copy(final T[] array) {
        if (array == null) {
            return null;
        } else {
            return Arrays.copyOf(array, array.length);
        }
    }
}

Related

  1. arrayCopyWithRemoval(Object[] src, Object[] dst, int idxToRemove)
  2. Arrays_copyOf(int[] pos, int length)
  3. copy(byte[] bytes)
  4. copy(byte[] data, int from)
  5. copy(double[][] a)
  6. copy(final byte[] bytes)
  7. copy(final byte[] inBytes)
  8. copy(int[] array)
  9. copy(int[] array)