Class ImmutableList<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,List<E>,RandomAccess,SequencedCollection<E>
List implementation.
Does not permit null elements.
Unlike
invalid reference
Collections#unmodifiableList
ImmutableList contains its own private data and will never change.
ImmutableList is convenient for public static final lists
("constant lists") and also lets you easily make a "defensive copy" of a list
provided to your class by a caller.
Note: Although this class is not final, it cannot be subclassed as it has no public or protected constructors. Thus, instances of this type are guaranteed to be immutable.
See the Guava User Guide article on immutable collections.
- Since:
- 2.0 (imported from Google Collections Library)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDeprecated.The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023 -
Method Summary
Modifier and TypeMethodDescriptionfinal voidDeprecated.Unsupported operation.final booleanaddAll(int index, Collection<? extends E> newElements) Deprecated.Unsupported operation.final ImmutableList<E> asList()Deprecated.Returns this list instance.static <E> ImmutableList.Builder<E> builder()Deprecated.Returns a new builder.booleanDeprecated.static <E> ImmutableList<E> copyOf(E[] elements) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> copyOf(Collection<? extends E> elements) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> Deprecated.Returns an immutable list containing the given elements, in order.booleanDeprecated.inthashCode()Deprecated.intDeprecated.iterator()Deprecated.Returns an unmodifiable iterator across the elements in this collection.intlastIndexOf(Object object) Deprecated.Deprecated.listIterator(int index) Deprecated.static <E> ImmutableList<E> of()Deprecated.Returns the empty immutable list.static <E> ImmutableList<E> of(E element) Deprecated.Returns an immutable list containing a single element.static <E> ImmutableList<E> of(E e1, E e2) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> of(E e1, E e2, E e3) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) Deprecated.Returns an immutable list containing the given elements, in order.static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) Deprecated.Returns an immutable list containing the given elements, in order.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) Deprecated.Returns an immutable list containing the given elements, in order.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) Deprecated.Returns an immutable list containing the given elements, in order.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) Deprecated.Returns an immutable list containing the given elements, in order.final Eremove(int index) Deprecated.Unsupported operation.reverse()Deprecated.Returns a view of this immutable list in reverse order.final EDeprecated.Unsupported operation.subList(int fromIndex, int toIndex) Deprecated.Returns an immutable list of the elements between the specifiedfromIndex, inclusive, andtoIndex, exclusive.Methods inherited from class com.google.common.collect.ImmutableCollection
add, addAll, clear, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, size, toStringMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
add, addAll, addFirst, addLast, clear, containsAll, get, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, size, sort, spliterator, toArray, toArray
-
Method Details
-
of
Deprecated.Returns the empty immutable list. This set behaves and performs comparably to, and is preferable mainly for consistency and maintainability of your code.invalid reference
Collections#emptyList -
of
Deprecated.Returns an immutable list containing a single element. This list behaves and performs comparably to, but will not accept a null element. It is preferable mainly for consistency and maintainability of your code.invalid reference
Collections#singleton- Throws:
NullPointerException- ifelementis null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
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) Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null
-
of
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) Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any element is null- Since:
- 3.0 (source-compatible since 2.0)
-
copyOf
Deprecated.Returns an immutable list containing the given elements, in order. Ifelementsis aCollection, this method behaves exactly ascopyOf(Collection); otherwise, it behaves exactly ascopyOf(elements.iterator().- Throws:
NullPointerException- if any ofelementsis null
-
copyOf
Deprecated.Returns an immutable list containing the given elements, in order.Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
Note that if
listis aList<String>, thenImmutableList.copyOf(list)returns anImmutableList<String>containing each of the strings inlist, while ImmutableList.of(list)} returns anImmutableList<List<String>>containing one element (the given list itself).This method is safe to use even when
elementsis a synchronized or concurrent collection that is currently being modified by another thread.- Throws:
NullPointerException- if any ofelementsis null
-
copyOf
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any ofelementsis null
-
copyOf
Deprecated.Returns an immutable list containing the given elements, in order.- Throws:
NullPointerException- if any ofelementsis null- Since:
- 3.0
-
iterator
Deprecated.Description copied from class:ImmutableCollectionReturns an unmodifiable iterator across the elements in this collection. -
listIterator
Deprecated.- Specified by:
listIteratorin interfaceList<E>
-
listIterator
Deprecated.- Specified by:
listIteratorin interfaceList<E>
-
indexOf
Deprecated. -
lastIndexOf
Deprecated.- Specified by:
lastIndexOfin interfaceList<E>
-
contains
Deprecated.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classImmutableCollection<E>
-
subList
Deprecated.Returns an immutable list of the elements between the specifiedfromIndex, inclusive, andtoIndex, exclusive. (IffromIndexandtoIndexare equal, the empty immutable list is returned.) -
addAll
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the list unmodified.- Specified by:
addAllin interfaceList<E>- Throws:
UnsupportedOperationException- always
-
set
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the list unmodified.- Specified by:
setin interfaceList<E>- Throws:
UnsupportedOperationException- always
-
add
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the list unmodified.- Specified by:
addin interfaceList<E>- Throws:
UnsupportedOperationException- always
-
remove
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the list unmodified.- Specified by:
removein interfaceList<E>- Throws:
UnsupportedOperationException- always
-
asList
Deprecated.Returns this list instance.- Overrides:
asListin classImmutableCollection<E>- Since:
- 2.0
-
reverse
Deprecated.Returns a view of this immutable list in reverse order. For example,ImmutableList.of(1, 2, 3).reverse()is equivalent toImmutableList.of(3, 2, 1).- Returns:
- a view of this immutable list in reverse order
- Since:
- 7.0
-
equals
Deprecated. -
hashCode
public int hashCode()Deprecated. -
builder
Deprecated.Returns a new builder. The generated builder is equivalent to the builder created by theImmutableList.Builderconstructor.
-