Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> ArrayList<T> asArrayList(T... array) {
        ArrayList<T> result = new ArrayList<T>();
        if (array != null) {
            Collections.addAll(result, array);
        }
        return result;
    }

    public static String[] addAll(String[] array1, String[] array2) {
        if (array1 == null) {
            return clone(array2);
        } else if (array2 == null) {
            return clone(array1);
        }
        String[] joinedArray = (String[]) Array.newInstance(array1.getClass().getComponentType(),
                array1.length + array2.length);
        System.arraycopy(array1, 0, joinedArray, 0, array1.length);
        System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
        return joinedArray;
    }

    public static String[] clone(Object[] array) {
        if (array == null) {
            return null;
        }
        return (String[]) array.clone();
    }
}