com.google.inject.internal.util
Class Lists

java.lang.Object
  extended by com.google.inject.internal.util.Lists

public final class Lists
extends Object

Static utility methods pertaining to List instances. Also see this class's counterparts Sets and Maps.

Author:
Kevin Bourrillion, Mike Bostock

Method Summary
static
<E> ArrayList<E>
newArrayList()
          Creates an empty ArrayList instance.
static
<E> ArrayList<E>
newArrayList(E... elements)
          Creates an ArrayList instance containing the given elements.
static
<E> ArrayList<E>
newArrayList(E first, E[] rest)
          Returns an unmodifiable list containing the specified first element and the additional elements.
static
<E> ArrayList<E>
newArrayList(Iterable<? extends E> elements)
          Creates an ArrayList instance containing the given elements.
static
<E> ArrayList<E>
newArrayList(Iterator<? extends E> elements)
          Creates an ArrayList instance containing the given elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newArrayList

public static <E> ArrayList<E> newArrayList()
Creates an empty ArrayList instance.

Note: if you need an immutable empty list, use Collections.emptyList() instead.

Returns:
a new, empty ArrayList

newArrayList

public static <E> ArrayList<E> newArrayList(E... elements)
Creates an ArrayList instance containing the given elements.

Note: if you need an immutable List, use ImmutableList instead.

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

List<Base> list = Lists.newArrayList(sub1, sub2);

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

List<Base> list = Lists.<Base>newArrayList(sub1, sub2);

Parameters:
elements - the elements that the list should contain, in order
Returns:
a new ArrayList containing those elements

newArrayList

public static <E> ArrayList<E> newArrayList(Iterable<? extends E> elements)
Creates an ArrayList instance containing the given elements.

Parameters:
elements - the elements that the list should contain, in order
Returns:
a new ArrayList containing those elements

newArrayList

public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements)
Creates an ArrayList instance containing the given elements.

Parameters:
elements - the elements that the list should contain, in order
Returns:
a new ArrayList containing those elements

newArrayList

public static <E> ArrayList<E> newArrayList(@Nullable
                                            E first,
                                            E[] rest)
Returns an unmodifiable list containing the specified first element and the additional elements.



Copyright © 2006-2011 Google, Inc.. All Rights Reserved.