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 Object expand(Object a) {
        Class cl = a.getClass();

        if (!cl.isArray()) {
            return null;
        }

        int length = Array.getLength(a);
        int newLength = length + 1; // 50% more
        Class componentType = a.getClass().getComponentType();
        Object newArray = Array.newInstance(componentType, newLength);

        System.arraycopy(a, 0, newArray, 0, length);
        return newArray;
    }
}