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

public abstract Class ImmutableList<E>

extends ImmutableCollection<E>
implements List<E>, RandomAccess
Class Inheritance
All Implemented Interfaces
java.util.RandomAccess, java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
com.google.common.collect.ImmutableList.SubList, com.google.common.collect.ImmutableList.ReverseImmutableList, com.google.common.collect.ImmutableRangeSet.ComplementRanges, com.google.common.collect.JdkBackedImmutableBiMap.InverseEntries, com.google.common.collect.Lists.StringAsImmutableList, com.google.common.collect.RegularImmutableList, com.google.common.collect.RegularImmutableMap.Values, com.google.common.collect.RegularImmutableTable.Values, com.google.common.collect.SingletonImmutableList, com.google.common.collect.ImmutableAsList
Annotations
@GwtCompatible
serializable:true
emulated:true
@SuppressWarnings:serial
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkElementIndex, .Preconditions.checkNotNull, .Preconditions.checkPositionIndexes, com.google.common.collect.CollectPreconditions.checkNonnegative, .ObjectArrays.checkElementsNotNull, .RegularImmutableList.EMPTY, java.util.Objects.requireNonNull

A List whose contents will never change, with many other important properties detailed at ImmutableCollection.

See the Guava User Guide article on immutable collections.

Author
Kevin Bourrillion
Since
2.0
See Also
ImmutableMap, ImmutableSet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImmutableList.Builder<E>

A builder for creating immutable list instances, especially public static final lists ("constant lists").

private static class
pack-priv static class
pack-priv class

Field Summary

Inherited from com.google.common.collect.ImmutableCollection:
SPLITERATOR_CHARACTERISTICS

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final void
add(int
index at which the specified element is to be inserted
index
,
E
element to be inserted
element
)

Implements java.util.List.add.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the list unmodified.
public final boolean
addAll(int
index at which to insert the first element from the specified collection
index
,
Collection<? extends E>
collection containing elements to be added to this list
newElements
)

Implements java.util.List.addAll.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the list unmodified.
pack-priv static <E> ImmutableList<E>
asImmutableList(Object[] elements)

Views the array as an immutable list.

pack-priv static <E> ImmutableList<E>
asImmutableList(@Nullable Object[] elements, int length)

Views the array as an immutable list.

public final ImmutableList<E>
asList()

Overrides com.google.common.collect.ImmutableCollection.asList.

Deprecated There is no reason to use this; it always returns this.
Returns this list instance.
public static <E> ImmutableList.Builder<E>
builder()

Returns a new builder.

public static <E> ImmutableList.Builder<E>
builderWithExpectedSize(int expectedSize)

Returns a new builder, expecting the specified number of elements to be added.

private static <E> ImmutableList<E>
construct(Object... elements)

Views the array as an immutable list.

public boolean
contains(Object
element whose presence in this list is to be tested
object
)

Implements abstract com.google.common.collect.ImmutableCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Returns true if this list contains the specified element.
pack-priv int
copyIntoArray(@Nullable Object[] dst, int offset)

public static <E> ImmutableList<E>
copyOf(Iterable<? extends E> elements)

Returns an immutable list containing the given elements, in order.

public static <E> ImmutableList<E>
copyOf(Collection<? extends E>
a Collection from which elements are drawn, must be non-null
elements
)

Hides java.util.List.copyOf.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
copyOf(Iterator<? extends E> elements)

Returns an immutable list containing the given elements, in order.

public static <E> ImmutableList<E>
copyOf(E[] elements)

Returns an immutable list containing the given elements, in order.

public boolean
equals(Object
the object to be compared for equality with this list
obj
)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.
public void
forEach(Consumer<? super E>
The action to be performed for each element
consumer
)

Overrides default java.lang.Iterable.forEach.

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.
public int
indexOf(Object
element to search for
object
)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public UnmodifiableIterator<E>
iterator()

Implements abstract com.google.common.collect.ImmutableCollection.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Returns an iterator over the elements in this list in proper sequence.
public int
lastIndexOf(Object
element to search for
object
)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public UnmodifiableListIterator<E>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public UnmodifiableListIterator<E>
listIterator(int
index of the first element to be returned from the list iterator (by a call to next)
index
)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public static <E> ImmutableList<E>
of()

Hides java.util.List.of.

Returns the empty immutable list.
public static <E> ImmutableList<E>
of(E
the single element
element
)

Hides java.util.List.of.

Returns an immutable list containing a single element.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
,
E
the sixth element
e6
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
,
E
the sixth element
e6
,
E
the seventh element
e7
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
,
E
the sixth element
e6
,
E
the seventh element
e7
,
E
the eighth element
e8
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
,
E
the sixth element
e6
,
E
the seventh element
e7
,
E
the eighth element
e8
,
E
the ninth element
e9
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
,
E
the sixth element
e6
,
E
the seventh element
e7
,
E
the eighth element
e8
,
E
the ninth element
e9
,
E
the tenth element
e10
)

Hides java.util.List.of.

Returns an immutable list containing the given elements, in order.
public static <E> ImmutableList<E>
of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11)

Returns an immutable list containing the given elements, in order.

public static <E> ImmutableList<E>
of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11, E e12, E... others)

Returns an immutable list containing the given elements, in order.

private void
public final E
remove(int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the list unmodified.
public final void
replaceAll(UnaryOperator<E>
the operator to apply to each element
operator
)

Overrides default java.util.List.replaceAll.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the list unmodified.
public ImmutableList<E>

Returns:

a view of this immutable list in reverse order
reverse
()

Returns a view of this immutable list in reverse order.

public final E
set(int
index of the element to replace
index
,
E
element to be stored at the specified position
element
)

Implements java.util.List.set.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the list unmodified.
public final void
sort(@Nullable Comparator<? super E>
the Comparator used to compare list elements. A null value indicates that the elements' natural ordering should be used
c
)

Overrides default java.util.List.sort.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the list unmodified.
public static <E extends Comparable<? super E>> ImmutableList<E>
sortedCopyOf(Iterable<? extends E> elements)

Returns an immutable list containing the given elements, sorted according to their natural order.

public static <E> ImmutableList<E>
sortedCopyOf(Comparator<? super E> comparator, Iterable<? extends E> elements)

Returns an immutable list containing the given elements, in sorted order relative to the specified comparator.

public Spliterator<E>
public ImmutableList<E>
subList(int
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
toIndex
)

Implements java.util.List.subList.

Returns an immutable list of the elements between the specified fromIndex, inclusive, and toIndex, exclusive.
pack-priv ImmutableList<E>
subListUnchecked(int fromIndex, int toIndex)

Called by the default implementation of subList when toIndex - fromIndex > 1, after index validation has already been performed.

public static <E> Collector<E, ?, ImmutableList<E>>
toImmutableList()

Returns a Collector that accumulates the input elements into a new ImmutableList, in encounter order.

pack-priv Object
Inherited from com.google.common.collect.ImmutableCollection:
addaddAllclearcopyIntoArrayinternalArrayinternalArrayEndinternalArrayStartisPartialViewremoveremoveAllremoveIfretainAlltoArraytoArray