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;
import java.util.List;

public class Main {
    /**
     * Converts a collection to a list by either casting or creating a concrete
     * list depending on the type of collection given.
     * @param <T> The type of the elements in the collection.
     * @param c the collection. If <code>null</code>, <code>null</code> is
     *        returned.
     * @return {@link List} containing the same elements as the given
     *         {@link Collection} param.
     */
    public static <T> List<T> listFromCollection(Collection<T> c) {
        if (c == null)
            return null;
        if (c.size() < 1) {
            return new ArrayList<T>(0);
        }
        return (c instanceof List<?>) ? (List<T>) c : new ArrayList<T>(c);
    }
}