Here you can find the source of toList(Collection
public static <E> List<E> toList(Collection<E> collection)
//package com.java2s; /*//from w ww .ja v a 2s. co m * MiscUtils.java * * Copyright (c) 1998 - 2006 BusinessTechnology, Ltd. * All rights reserved * * This program is the proprietary and confidential information * of BusinessTechnology, Ltd. and may be used and disclosed only * as authorized in a license agreement authorizing and * controlling such use and disclosure * * Millennium ERP system. * */ import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /** * Create a list from passed objX parameters * * @return The resulting List */ public static <T> List<T> toList(T obj1) { List<T> list = new ArrayList<T>(1); list.add(obj1); return list; } /** * Create a list from passed objX parameters * * @return The resulting List */ public static <E> List<E> toList(E obj1, E obj2) { List<E> list = new ArrayList<E>(2); list.add(obj1); list.add(obj2); return list; } /** * Create a list from passed objX parameters * * @return The resulting List */ public static <E> List<E> toList(E obj1, E obj2, E obj3) { List<E> list = new ArrayList<E>(3); list.add(obj1); list.add(obj2); list.add(obj3); return list; } /** * Create a list from passed objX parameters * * @return The resulting List */ public static <E> List<E> toList(E obj1, E obj2, E obj3, E obj4) { List<E> list = new ArrayList<E>(4); list.add(obj1); list.add(obj2); list.add(obj3); list.add(obj4); return list; } /** * Create a list from passed objX parameters * * @return The resulting List */ public static <E> List<E> toList(E obj1, E obj2, E obj3, E obj4, E obj5) { List<E> list = new ArrayList<E>(5); list.add(obj1); list.add(obj2); list.add(obj3); list.add(obj4); list.add(obj5); return list; } /** * Create a list from passed objX parameters * * @return The resulting List */ public static <E> List<E> toList(E obj1, E obj2, E obj3, E obj4, E obj5, E obj6) { List<E> list = new ArrayList<E>(6); list.add(obj1); list.add(obj2); list.add(obj3); list.add(obj4); list.add(obj5); list.add(obj6); return list; } public static <E> List<E> toList(Collection<E> collection) { if (collection == null) return null; if (collection instanceof List) { return (List<E>) collection; } else { return new ArrayList<E>(collection); } } }