Top Description Inners Constructors Methods
com.google.common.collect

public final Class Lists

extends Object
Class Inheritance
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkElementIndex, .Preconditions.checkNotNull, .Preconditions.checkPositionIndex, .Preconditions.checkPositionIndexes, .Preconditions.checkState, com.google.common.collect.CollectPreconditions.checkNonnegative, .CollectPreconditions.checkRemove

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

See the Guava User Guide article on Lists.

Authors
Kevin Bourrillion, Mike Bostock, Louis Wasserman
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
Lists.TransformingRandomAccessList<F extends @Nullable Object, T extends @Nullable Object>

Implementation of a transforming random access list.

private static class
Lists.TransformingSequentialList<F extends @Nullable Object, T extends @Nullable Object>

Implementation of a sequential transforming list.

private static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <E extends @Nullable Object> boolean
addAllImpl(List<E> list, int index, Iterable<? extends E> elements)

An implementation of List#addAll(int, Collection).

public static <E extends @Nullable Object> List<E>

Returns:

an unmodifiable list containing the specified elements
asList
(E
the first element
first
,
E[]
an array of additional elements, possibly empty
rest
)

Returns an unmodifiable list containing the specified first element and backed by the specified array of additional elements.

public static <E extends @Nullable Object> List<E>

Returns:

an unmodifiable list containing the specified elements
asList
(E
the first element
first
,
E
the second element
second
,
E[]
an array of additional elements, possibly empty
rest
)

Returns an unmodifiable list containing the specified first and second element, and backed by the specified array of additional elements.

public static <
any common base class shared by all axes (often just Object)
B
>
List<List<B>>

Returns:

the Cartesian product, as an immutable list containing immutable lists
cartesianProduct
(List<? extends List<? extends B>>
the lists to choose elements from, in the order that the elements chosen from those lists should appear in the resulting lists
lists
)

Returns every possible list that can be formed by choosing one element from each of the given lists in order; the "n-ary Cartesian product" of the lists.

public static <
any common base class shared by all axes (often just Object)
B
>
List<List<B>>

Returns:

the Cartesian product, as an immutable list containing immutable lists
cartesianProduct
(List<? extends B>...
the lists to choose elements from, in the order that the elements chosen from those lists should appear in the resulting lists
lists
)

Returns every possible list that can be formed by choosing one element from each of the given lists in order; the "n-ary Cartesian product" of the lists.

pack-priv static <T extends @Nullable Object> List<T>
cast(Iterable<T> iterable)

Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557

public static ImmutableList<Character>
charactersOf(String string)

Returns a view of the specified string as an immutable list of Character values.

public static List<Character>

Returns:

an List<Character> view of the character sequence
charactersOf
(CharSequence
the character sequence to view as a List of characters
sequence
)

Returns a view of the specified CharSequence as a List<Character>, viewing sequence as a sequence of Unicode code units.

pack-priv static int
computeArrayListCapacity(int arraySize)

pack-priv static boolean
equalsImpl(List<?> thisList, Object other)

An implementation of List#equals(Object).

pack-priv static int
hashCodeImpl(List<?> list)

An implementation of List#hashCode().

pack-priv static int
indexOfImpl(List<?> list, Object element)

An implementation of List#indexOf(Object).

private static int
indexOfRandomAccess(List<?> list, Object element)

pack-priv static int
lastIndexOfImpl(List<?> list, Object element)

An implementation of List#lastIndexOf(Object).

private static int
pack-priv static <E extends @Nullable Object> ListIterator<E>
listIteratorImpl(List<E> list, int index)

Returns an implementation of List#listIterator(int).

public static <E extends @Nullable Object> ArrayList<E>
newArrayList()

Creates a mutable, empty ArrayList instance (for Java 6 and earlier).

public static <E extends @Nullable Object> ArrayList<E>
newArrayList(E... elements)

Creates a mutable ArrayList instance containing the given elements.

public static <E extends @Nullable Object> ArrayList<E>
newArrayList(Iterable<? extends E> elements)

Creates a mutable ArrayList instance containing the given elements; a very thin shortcut for creating an empty list then calling Iterables#addAll.

public static <E extends @Nullable Object> ArrayList<E>
newArrayList(Iterator<? extends E> elements)

Creates a mutable ArrayList instance containing the given elements; a very thin shortcut for creating an empty list and then calling Iterators#addAll.

public static <E extends @Nullable Object> ArrayList<E>

Returns:

a new, empty ArrayList which is guaranteed not to resize itself unless its size reaches initialArraySize + 1
newArrayListWithCapacity
(int
the exact size of the initial backing array for the returned array list (ArrayList documentation calls this value the "capacity")
initialArraySize
)

Creates an ArrayList instance backed by an array with the specified initial size; simply delegates to ArrayList#ArrayList(int).

public static <E extends @Nullable Object> ArrayList<E>

Returns:

a new, empty ArrayList, sized appropriately to hold the estimated number of elements
newArrayListWithExpectedSize
(int
an estimate of the eventual List#size() of the new list
estimatedSize
)

Creates an ArrayList instance to hold estimatedSize elements, plus an unspecified amount of padding; you almost certainly mean to call newArrayListWithCapacity (see that method for further advice on usage).

public static <E extends @Nullable Object> CopyOnWriteArrayList<E>

Returns:

a new, empty CopyOnWriteArrayList
newCopyOnWriteArrayList
()

Creates an empty CopyOnWriteArrayList instance.

public static <E extends @Nullable Object> CopyOnWriteArrayList<E>

Returns:

a new CopyOnWriteArrayList containing those elements
newCopyOnWriteArrayList
(Iterable<? extends E>
the elements that the list should contain, in order
elements
)

Creates a CopyOnWriteArrayList instance containing the given elements.

public static <E extends @Nullable Object> LinkedList<E>
newLinkedList()

Creates a mutable, empty LinkedList instance (for Java 6 and earlier).

public static <E extends @Nullable Object> LinkedList<E>
newLinkedList(Iterable<? extends E> elements)

Creates a mutable LinkedList instance containing the given elements; a very thin shortcut for creating an empty list then calling Iterables#addAll.

public static <T extends @Nullable Object> List<List<T>>

Returns:

a list of consecutive sublists
partition
(List<T>
the list to return consecutive sublists of
list
,
int
the desired size of each sublist (the last may be smaller)
size
)

Returns consecutive sublists of a list, each of the same size (the final list may be smaller).

public static <T extends @Nullable Object> List<T>
reverse(List<T> list)

Returns a reversed view of the specified list.

pack-priv static <E extends @Nullable Object> List<E>
subListImpl(final List<E> list, int fromIndex, int toIndex)

An implementation of List#subList(int, int).

public static <F extends @Nullable Object, T extends @Nullable Object> List<T>
transform(List<F> fromList, Function<? super F, ? extends T> function)

Returns a list that applies function to each element of fromList.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait