Here you can find the source of copyOf(Object[] values, int nlen)
Parameter | Description |
---|---|
values | the old array. |
nlen | the length of the new array. |
public static Object[] copyOf(Object[] values, int nlen)
//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; } }