FileDocCategorySizeDatePackage
Lists.javaAPI DocAndroid 1.5 API2184Wed May 06 22:41:56 BST 2009com.google.android.collect

Lists

public class Lists extends Object
Provides static methods for creating {@code List} instances easily, and other utility methods for working with lists.

Fields Summary
Constructors Summary
Methods Summary
public static java.util.ArrayListnewArrayList()
Creates an empty {@code ArrayList} instance.

Note: if you only need an immutable empty List, use {@link Collections#emptyList} instead.

return
a newly-created, initially-empty {@code ArrayList}

        return new ArrayList<E>();
    
public static java.util.ArrayListnewArrayList(E elements)
Creates a resizable {@code ArrayList} instance containing the given elements.

Note: due to a bug in javac 1.5.0_06, we cannot support the following:

{@code List list = Lists.newArrayList(sub1, sub2);}

where {@code sub1} and {@code sub2} are references to subtypes of {@code Base}, not of {@code Base} itself. To get around this, you must use:

{@code List list = Lists.newArrayList(sub1, sub2);}

param
elements the elements that the list should contain, in order
return
a newly-created {@code ArrayList} containing those elements

        int capacity = (elements.length * 110) / 100 + 5;
        ArrayList<E> list = new ArrayList<E>(capacity);
        Collections.addAll(list, elements);
        return list;