Java Collection to List toList(Collection c)

Here you can find the source of toList(Collection c)

Description

to List

License

Open Source License

Declaration

public static <E extends Object> List<E> toList(Collection<E> c) 

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 {
    public static <E extends Object> List<E> toList(E[] e) {
        if (e == null)
            return new ArrayList<E>(0); // TODO temp
        ArrayList<E> o = new ArrayList<E>(e.length);
        for (int i = 0; i < e.length; i++)
            o.add(e[i]);//  w w  w  .ja  va 2 s . c  om
        return o;
    }

    public static <E extends Object> List<E> toList(E e) {
        ArrayList<E> o = new ArrayList<E>(1);
        o.add(e);
        return o;
    }

    public static <E extends Object> List<E> toList(Collection<E> c) {
        if (c instanceof List)
            return (List<E>) c;
        ArrayList<E> o = new ArrayList<E>(c.size());
        for (E e : c)
            o.add(e);
        return o;
    }
}

Related

  1. newList(final Collection collection)
  2. newList(final Collection objects)
  3. toList(Collection addresses, char separator)
  4. toList(Collection collection)
  5. toList(Collection collection)
  6. toList(Collection collection)
  7. toList(Collection lines)
  8. toList(Collection c)
  9. toList(Collection c)