Java Collection to List newList(final Collection collection)

Here you can find the source of newList(final Collection collection)

Description

New list.

License

Open Source License

Parameter

Parameter Description
T the generic type
collection the collection

Return

the list

Declaration

public static <T> List<T> newList(final Collection<T> collection) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *******************************************************************************/

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    /**//  w ww .j ava 2  s  . com
     * New list.
     *
     * @param <T> the generic type
     * @param objects the objects
     * @return the list
     */
    public static <T> List<T> newList(final T... objects) {
        return list(objects);
    }

    /**
     * New list.
     *
     * @param <T> the generic type
     * @param collection the collection
     * @return the list
     */
    public static <T> List<T> newList(final Collection<T> collection) {
        return list(collection);
    }

    /**
     * List.
     *
     * @param <T> the generic type
     * @param objects the objects
     * @return the list
     */
    public static <T> List<T> list(final T... objects) {
        return array(objects);
    }

    /**
     * List.
     *
     * @param <T> the generic type
     * @param collection the collection
     * @return the list
     */
    public static <T> List<T> list(final Collection<T> collection) {
        final List<T> list = new ArrayList<T>();
        if (collection != null && collection.size() > 0)
            list.addAll(collection);
        return list;
    }

    /**
     * Array.
     *
     * @param <T> the generic type
     * @param objects the objects
     * @return the list
     */
    public static <T> List<T> array(final T... objects) {
        final List<T> list = new ArrayList<T>();
        add(list, objects);
        return list;
    }

    /**
     * Array.
     *
     * @param <T> the generic type
     * @param collection the collection
     * @return the list
     */
    public static <T> List<T> array(final Collection<T> collection) {
        final List<T> list = new ArrayList<T>();
        if (collection != null && collection.size() > 0)
            list.addAll(collection);
        return list;
    }

    /**
     * Adds the.
     *
     * @param <T> the generic type
     * @param list the list
     * @param objects the objects
     * @return the list
     */
    public static <T> List<T> add(final List<T> list, final T... objects) {
        if (objects == null)
            return list;
        for (final T object : objects)
            list.add(object);
        return list;
    }
}

Related

  1. convertCollectionToList(Collection coll)
  2. convertCollectionToList(Collection collection)
  3. convertCollectionToList(final Collection collection)
  4. convertCollectionToSQL(List listId)
  5. newList(final Collection elements)
  6. newList(final Collection objects)
  7. toList(Collection addresses, char separator)
  8. toList(Collection collection)
  9. toList(Collection collection)