append element to enlarged array - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

append element to enlarged array

Demo Code


//package com.java2s;

import java.util.Arrays;

public class Main {
    public static <T> T[] append(T[] array, T element) {
        final int N = array.length;
        array = Arrays.copyOf(array, N + 1);
        array[N] = element;//w ww . j a  v a  2s. c  o  m

        return array;
    }
}

Related Tutorials