Java Array Range Copy copyOf(Object[] values, int nlen)

Here you can find the source of copyOf(Object[] values, int nlen)

Description

Create a copy of the specified Object[] array, with the specified new length.

License

Open Source License

Parameter

Parameter Description
values the old array.
nlen the length of the new array.

Return

the new array.

Declaration

public static Object[] copyOf(Object[] values, int nlen) 

Method Source Code

//package com.java2s;
/*//from ww  w . j a va  2 s.c o m
 * Copyright 2013-2015 Colby Skeggs
 *
 * This file is part of the CCRE, the Common Chicken Runtime Engine.
 *
 * The CCRE is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * The CCRE is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with the CCRE.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Create a copy of the specified Object[] array, with the specified new
     * length. Added indexes will be filled with null.
     *
     * @param values the old array.
     * @param nlen the length of the new array.
     * @return the new array.
     */
    public static Object[] copyOf(Object[] values, int nlen) {
        Object[] out = new Object[nlen];
        if (nlen < values.length) {
            System.arraycopy(values, 0, out, 0, nlen);
        } else {
            System.arraycopy(values, 0, out, 0, values.length);
        }
        return out;
    }
}

Related

  1. copyOf(int[] src, int size)
  2. copyOf(int[][] pixels)
  3. copyOf(Integer[] original)
  4. copyOf(Object src, int newLength)
  5. copyOf(Object[] array, int newLength)
  6. copyOf(String[] data, int newLength)
  7. copyOf(String[] original, int newLength)
  8. copyOf(T[] oriArray, int newArraySize, int startOffset)
  9. copyOfArray(int[] a)