Here you can find the source of asList(Collection
public static <T> List<T> asList(Collection<T> c)
//package com.java2s; /******************************************************************************* * Copyright (c) 2008 The University of York. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * /* w w w.j a v a2 s. co m*/ * Contributors: * Dimitrios Kolovos - initial API and implementation ******************************************************************************/ import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static List<?> asList(Object o) { if (o instanceof List) { return (List<?>) o; } else if (o instanceof Collection) { List<Object> list = createDefaultList(); list.addAll((Collection<?>) o); return list; } else { List<Object> list = createDefaultList(); list.add(o); return list; } } public static <T> List<T> asList(Collection<T> c) { if (c instanceof List) { return (List<T>) c; } else { ArrayList<T> copy = new ArrayList<T>(); copy.addAll(c); return copy; } } public static <T> List<T> createDefaultList() { return new ArrayList<T>(); } }