Java Array Copy copy(int[] array)

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

Description

Returns a deep copy of the input array .

License

Open Source License

Parameter

Parameter Description
array Input array

Return

Deep copy of array

Declaration

public static int[] copy(int[] array) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Pablo Pavon-Marino.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * Contributors://w w w .j a  v a 2 s .  co  m
 *     Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1
 *     Pablo Pavon-Marino - from version 0.4.0 onwards
 ******************************************************************************/

import java.util.*;

public class Main {
    /**
     * Returns a deep copy of the input {@code array}.
     *
     * @param array Input array
     * @return Deep copy of {@code array}
     */
    public static int[] copy(int[] array) {
        return Arrays.copyOf(array, array.length);
    }

    /**
     * Returns a deep copy of the input {@code array}.
     *
     * @param array Input array
     * @return Deep copy of {@code array}
     */
    public static int[][] copy(int[][] array) {
        int[][] out = new int[array.length][];
        for (int rowId = 0; rowId < array.length; rowId++)
            out[rowId] = copy(array[rowId]);

        return out;
    }
}

Related

  1. copy(double[][] a)
  2. copy(final boolean[] array)
  3. copy(final byte[] bytes)
  4. copy(final byte[] inBytes)
  5. copy(int[] array)
  6. copy(int[][] input)
  7. copy(long[] array)
  8. copy(long[] v)
  9. copy(T[] array)