Java Collection to List newList(final Collection elements)

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

Description

new List

License

Open Source License

Declaration

public static <T> List<T> newList(final Collection<? extends T> elements) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2014 Alexander Kerner. 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.//from  w w w  .ja v  a  2 s . co  m
 ******************************************************************************/

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

import java.util.List;

public class Main {
    public static <T> List<T> newList() {
        return new ArrayList<T>();
    }

    public static <T> List<T> newList(final Collection<? extends T> elements) {
        return new ArrayList<T>(elements);
    }

    public static <T> List<T> newList(final Collection<? extends T>... elements) {
        final List<T> result = newList();
        for (final Collection<? extends T> c : elements) {
            result.addAll(c);
        }
        return result;
    }

    public static <T> List<T> newList(final T... elements) {
        return Arrays.asList(elements);
    }

    @SuppressWarnings("unchecked")
    public static <T> List<T> asList(final Collection<? extends T> collection) {
        List<T> result;
        if (collection instanceof List) {
            result = (List<T>) collection;
        } else {
            result = newList(collection);
        }
        return result;
    }
}

Related

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