Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;

import java.util.Collection;

public class Main {
    /**
     * Create an {@link ArrayList} with zero or more "objects".
     * @param objects
     * @return ArrayList<O>
     */
    @SafeVarargs
    public static <O> ArrayList<O> arrayList(O... objects) {
        ArrayList<O> list = new ArrayList<>();

        for (O object : objects) {
            list.add(object);
        }

        return list;
    }

    /**
     * Create an {@link ArrayList} from a given {@link Collection}
     * @param <O>
     * @param source
     * @return ArrayList<O>
     */
    public static <O> ArrayList<O> arrayList(Collection<O> source) {
        return new ArrayList<>(source);
    }
}