Interface ImmutableList<E extends @Nullable Object>

Type Parameters:
E - the type of elements contained in the list. The immutable list is covariant on its element type.
All Superinterfaces:
ImmutableCollection<E>, Iterable<E>
All Known Subinterfaces:
PersistentList<E>
All Known Implementing Classes:
ImmutableList.SubList

public interface ImmutableList<E extends @Nullable Object> extends ImmutableCollection<E>

A generic immutable ordered collection of elements. Methods in this interface support only read-only access to the immutable list.

Modification operations are supported through the PersistentList interface.

Implementors of this interface take responsibility to be immutable. Once constructed they must contain the same elements in the same order.

  • Method Details

    • from

      static <T extends @Nullable Object> ImmutableList<T> from(Iterable<T> iterable)

      Returns an immutable list containing all elements of the specified collection.

      If the specified collection is already an immutable list, returns it as is.

    • from

      static <T extends @Nullable Object> ImmutableList<T> from(T[] array)
      Returns an immutable list containing all elements of the specified array.
    • from

      static <T extends @Nullable Object> ImmutableList<T> from(Stream<? extends T> stream)
      Returns an immutable list containing all elements of the specified sequence.
    • from

      static ImmutableList<Character> from(CharSequence chars)
      Returns an immutable list containing all characters.
    • get

      E get(int index)
      Returns the element at the specified index in the list.
      Throws:
      IndexOutOfBoundsException - if index is less than zero or greater than or equal to size of this list.
    • indexOf

      int indexOf(E element)

      Returns the index of the first occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

      For lists containing more than Int.MAX_VALUE elements, a result of this function is unspecified.

    • lastIndexOf

      int lastIndexOf(E element)

      Returns the index of the last occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

      For lists containing more than Int.MAX_VALUE elements, a result of this function is unspecified.

    • listIterator

      ListIterator<E> listIterator()
      Returns a list iterator over the elements in this list (in proper sequence).
    • listIterator

      ListIterator<E> listIterator(int index)
      Returns a list iterator over the elements in this list (in proper sequence), starting at the specified index.
      Throws:
      IndexOutOfBoundsException - if index is less than zero or greater than or equal to size of this list.
    • subList

      default ImmutableList<E> subList(int fromIndex, int toIndex)

      Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive).

      The returned list is backed by this list.

      Throws:
      IndexOutOfBoundsException - if fromIndex is less than zero or toIndex is greater than the size of this list.
      IllegalArgumentException - if fromIndex is greater than toIndex.