Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.Array;

public class Main {

    public static <T> T[] addElement(T[] array, T element) {
        Class<?> ct = array.getClass().getComponentType();
        T[] newArray = (T[]) Array.newInstance(ct, array.length + 1);
        System.arraycopy(array, 0, newArray, 0, array.length);
        newArray[newArray.length - 1] = element;
        return newArray;
    }
}