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.Collections;

import java.util.List;

public class Main {
    /**
     * Crates an unmodifiable list filled with the given values.
     * 
     * @param <T>
     *            the list's element type.
     * @param values
     *            the values.
     * @return the list.
     */
    @SafeVarargs
    public static <T> List<T> createUnmodifiableList(final T... values) {
        return Collections.unmodifiableList(createArrayList(values));
    }

    /**
     * Creates an <code>ArrayList</code> filled with the given values. The
     * list's capacity will match its size.
     * 
     * @param <T>
     *            the list's element type.
     * @param values
     *            the initial values.
     * @return the list.
     */
    @SafeVarargs
    public static <T> List<T> createArrayList(final T... values) {
        final List<T> l = new ArrayList<T>(values.length);
        for (final T t : values) {
            l.add(t);
        }
        return l;
    }
}