Java Array Resize resizeNoAutoInit(T[] oldarray, int newsize)

Here you can find the source of resizeNoAutoInit(T[] oldarray, int newsize)

Description

Resize an array without autoinitialization.

License

Open Source License

Parameter

Parameter Description
T a parameter
oldarray a parameter
newsize a parameter

Declaration


public static final <T> T[] resizeNoAutoInit(T[] oldarray, int newsize) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**//  w w w .  j a  v  a2s .  c  om
     * Resize an array without autoinitialization. Same as Arrays.copyOf(..), just
     * prints a message.
     *
     * @param <T>
     * @param oldarray
     * @param newsize
     * @return
     */

    public static final <T> T[] resizeNoAutoInit(T[] oldarray, int newsize) {

        // For non-autoinit types, this is enough.
        T[] tmp = Arrays.copyOf(oldarray, newsize);

        System.out
                .printf("Old array of type %s resized without auto-init. New capacity: %d\n",
                        tmp.getClass().getComponentType(), newsize);

        return tmp;

    }
}

Related

  1. prepend(T element, T[] array)
  2. prependArg(String args[], String newArg)
  3. prependZeros(int n, byte[] message)
  4. resize2(double[][] array, int newsize1, int newsize2, double padding)
  5. resizeArray(final T[] array, final int newSize)