Java Collection to List convertCollectionToList(Collection coll)

Here you can find the source of convertCollectionToList(Collection coll)

Description

Converts an instance of List to an instance of Collection.

License

Open Source License

Parameter

Parameter Description
T a parameter
coll An input Collection

Return

The input value coll if it is an instance of List. Else it will construct a list with the same values and return it.

Declaration

public static <T> List<T> convertCollectionToList(Collection<T> coll) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.List;

public class Main {
    /**//from w  w w  .  ja  v a  2  s  .com
     * Converts an instance of List to an instance of Collection.
     * @param <T>
     * @param coll An input Collection
     * @return The input value coll if it is an instance of List. Else it will construct a list with the same values and return it.
     **/
    public static <T> List<T> convertCollectionToList(Collection<T> coll) {
        if (coll instanceof List) {
            return (List<T>) coll;
        } else {
            List<T> theReturn = new ArrayList<T>(coll);
            return theReturn;
        }
    }
}

Related

  1. collectionToList(Collection theset)
  2. collectionToList(Collection source)
  3. collectionToList(Iterable c)
  4. convertCollectionToList(Collection c)
  5. convertCollectionToList(Collection collection)
  6. convertCollectionToList(final Collection collection)
  7. convertCollectionToSQL(List listId)
  8. newList(final Collection elements)