com.google.inject.internal
Class Lists

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

public final class Lists
extends java.lang.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> java.util.ArrayList<E>
newArrayList()
          Creates an empty ArrayList instance.
static
<E> java.util.ArrayList<E>
newArrayList(E... elements)
          Creates an ArrayList instance containing the given elements.
static
<E> java.util.ArrayList<E>
newArrayList(E first, E[] rest)
          Returns an unmodifiable list containing the specified first element and the additional elements.
static
<E> java.util.ArrayList<E>
newArrayList(java.lang.Iterable<? extends E> elements)
          Creates an ArrayList instance containing the given elements.
static
<E> java.util.ArrayList<E>
newArrayList(java.util.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> java.util.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> java.util.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> java.util.ArrayList<E> newArrayList(java.lang.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> java.util.ArrayList<E> newArrayList(java.util.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> java.util.ArrayList<E> newArrayList(@Nullable
                                                      E first,
                                                      E[] rest)
Returns an unmodifiable list containing the specified first element and the additional elements.



Copyright © 2011. All Rights Reserved.