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[] insert(T[] array, int index, T element) {
        T[] ret = (T[]) Array.newInstance(array.getClass().getComponentType(), array.length + 1);
        for (int i = 0; i < ret.length; ++i) {
            ret[i] = i < index ? array[i] : (i == index ? element : array[i - 1]);
        }
        return ret;
    }
}