Here you can find the source of resizeArray(final T[] array, final int newSize)
Parameter | Description |
---|---|
array | the array to be copied ("resized") |
newSize | the new size |
public static <T> T[] resizeArray(final T[] array, final int newSize)
//package com.java2s; /*/*w w w . j a v a 2s .c o m*/ * Copyright (C) 2011-2014 Brian Groenke * All rights reserved. * * This file is part of the 2DX Graphics Library. * * This Source Code Form is subject to the terms of the * Mozilla Public License, v. 2.0. If a copy of the MPL * was not distributed with this file, You can obtain one at * http://mozilla.org/MPL/2.0/. */ import java.util.Arrays; public class Main { /** * Copies the contents of the given array into an array of the specified * size. * * @param array * the array to be copied ("resized") * @param newSize * the new size * @return */ public static <T> T[] resizeArray(final T[] array, final int newSize) { return Arrays.copyOf(array, newSize); /* * Class<T> type = (Class<T>) array.getClass(); T[] narr = (T[]) * Array.newInstance(type, newSize); for(int i=0;i<narr.length;i++) { * if(i < array.length) narr[i] = array[i]; else narr[i] = null; } * return narr; */ } }